Struct GameRng
pub struct GameRng(/* private fields */);Expand description
Re-exported so callers of cases::try_finalize_item can supply its RNG
without depending on event_system directly.
Implementations§
§impl GameRng
impl GameRng
pub fn new(rng: StdRng) -> GameRng
pub fn from_entropy() -> GameRng
pub fn from_values(values: Vec<f64>) -> GameRng
pub fn from_values(values: Vec<f64>) -> GameRng
A deterministic source replaying values (cycling). Used by the test
harness so fight scripts get reproducible randomness through the native
fight_context.
pub fn from_entropy_recording() -> GameRng
pub fn from_entropy_recording() -> GameRng
An entropy source that records every f64 it draws. Draw against this
first, then call GameRng::recorded and feed the result into
GameRng::from_values to replay the same sequence. Returns the
default (empty) recording until used.
pub fn recorded(&self) -> Vec<f64>
pub fn recorded(&self) -> Vec<f64>
The sequence of f64 draws made so far. Empty for non-Recording
backends. Cloned out so the caller can build a Self::from_values
replay source from it.
pub fn random_bytes(&self) -> [u8; 16]
pub fn random_f64(&self) -> f64
pub fn random_index(&self, len: usize) -> usize
pub fn random_index(&self, len: usize) -> usize
Uniformly pick an index in [0, len), consuming exactly one f64
helper performed.
Prefer this over randint for picking a random element of
a collection. On the production Std backend randint draws via
StdRng::random_range (integer rejection sampling), which consumes a
different and variable amount of the RNG stream than a single f64 —
so it both picks a different element than floor(random() * len) would
for a given seed and desyncs every subsequent draw in the same handler.
The Fixed/Recording test backends map randint from a single f64,
so that divergence is invisible to tests. random_index is one f64 on
every backend, keeping selection identical across production and tests.