We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Would you like to add a choose_weighted function to the library?
fn choose_weighted<'a, T>(&mut self, values: &'a [T], weights: &[f32]) -> Option<&'a T> where Self: Sized, [−] Return a weighted-random element from values. Return None if values is empty. Example use rand::{thread_rng, Rng}; let choices = [20, 30, 40, 10]; let weights = [.60, 20, 15, 5]; let mut rng = thread_rng(); println!("{:?}", rng.choose_weighted(&choices, &weights));
The text was updated successfully, but these errors were encountered:
We already have WeightedChoice which does roughly this, though I'm tempted to remove the items ("choices") themselves and just return an index.
WeightedChoice
See also dhardy#82
Sorry, something went wrong.
No branches or pull requests
Would you like to add a choose_weighted function to the library?
The text was updated successfully, but these errors were encountered: