pub trait ChooseRandomly {
type Cache;
// Required methods
fn choose_randomly(fractions: &Vec<Self>) -> Result<usize>
where Self: Sized;
fn choose_randomly_create_cache<'a>(
fractions: impl Iterator<Item = &'a Self>,
) -> Result<Self::Cache>
where Self: Sized + 'a;
fn choose_randomly_cached(cache: &Self::Cache) -> usize
where Self: Sized;
}Required Associated Types§
Required Methods§
Sourcefn choose_randomly(fractions: &Vec<Self>) -> Result<usize>where
Self: Sized,
fn choose_randomly(fractions: &Vec<Self>) -> Result<usize>where
Self: Sized,
Return a random index from 0 (inclusive) to the length of the list (exclusive). The likelihood of each index to be returned is proportional to the value of the fraction at that index.
The fractions do not need to sum to 1.