Skip to main content

rand_weighted_choice

Macro rand_weighted_choice 

Source
macro_rules! rand_weighted_choice {
    ($rng:expr, $choices:expr, $weights:expr) => { ... };
}
Expand description

Selects a reference into $choices weighted by $weights.

ยงExamples

use vrd::{Random, rand_weighted_choice};

let mut rng = Random::from_u64_seed(42);
let choices = ["a", "b"];
let weights = [10, 90];
let pick = rand_weighted_choice!(rng, &choices, &weights);