Expand description
Weighted/uniform random draw helpers over [GameRng].
The implementations live in [event_system::rng] โ they are generic over
GameRng and std collections with nothing game-specific in them. Re-exported
here so the behaviors ports keep their mechanics::util:: paths, and so
every caller draws RNG through the same index/weight arithmetic.
Functionsยง
- drain_
random - Remove and return a uniformly-random element of
vec,Nonewhen empty. Same index formula asget_random_element, thenVec::removeโ so the remaining order is preserved and repeated draws sample without replacement. - get_
random_ element - Pick a uniformly-random element of
slice,Nonewhen empty. Index isfloor(random_f64() * len), clamped tolen - 1โ onef64draw, matchingGameRng::random_index. - rand_
round - Stochastic round of a non-integer value:
2.3yields3with probability0.3and2otherwise. Consumes onef64draw when there is a fraction to resolve, none whenvalueis already integral. - rand_
weight - Weighted pick: sum the weights, draw
random_f64() * sumonce, then walk the slice subtracting each weight until the accumulator goes non-positive.Nonewhen 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.