Skip to main content

get_random_item

Function get_random_item 

Source
pub fn get_random_item<'a, T, R: Random>(
    random: &mut R,
    items: &'a [T],
    weight: impl Fn(&T) -> i32,
) -> Option<&'a T>
Expand description

Picks an entry with probability proportional to its weight. A zero total weight returns None without consuming random values.

ยงPanics

Panics if the total weight is negative.