Skip to main content

Module rng

Module rng 

Source
Expand description

Seeded random numbers for a deterministic simulation.

SimRng is a PCG32 (XSH RR, 64-bit state) written in this crate, so its output is fixed by this file alone: same seed ⇒ same numbers on every platform and every dependency version. It is serialisable so a game’s state (and its RNG position) can be saved, rewound and replayed.

Game rules take a RandomSource, so tests can inject a ScriptedRng that returns a given list of rolls.

Structs§

ScriptedRng
A RandomSource that returns a fixed list of rolls, in order. For tests that need an exact trace of rolls. Percent rolls and roll_below draws come from two separate lists.
SimRng
The seeded simulation RNG, kept in the game’s state.

Traits§

RandomSource
Where game rules get their random numbers from.