Function rand_weight

pub fn rand_weight<'a, T>(
    random: &GameRng,
    weighted: &'a [(f64, T)],
) -> Option<&'a T>
Expand description

Weighted pick: sum the weights, draw random_f64() * sum once, then walk the slice subtracting each weight until the accumulator goes non-positive. None when the slice is empty or the weights sum to <= 0.0. The last element is the fallback if floating-point drift leaves the accumulator positive at the end.