metamon/generator/seed
Deterministic pseudo-random seed.
The implementation is the 32-bit “Marsaglia xorshift” PRNG. It uses only shifts and xors — no multiplication — so BEAM (bignum integers) and JavaScript (53-bit safe doubles) produce bit-identical streams. An LCG-style multiplier would overflow JavaScript’s double precision well before the 32-bit mask and cause subtle distribution drift.
Statistical quality is not the goal here — determinism and portability are. Property-based testing is well-served even by modest PRNGs because the failure search is shrinker-driven, not statistical.
Types
Values
pub fn next_int(s: Seed) -> #(Int, Seed)
Advance the seed once and return the next non-negative integer alongside the advanced seed.
pub fn next_int_in(s: Seed, lo: Int, hi: Int) -> #(Int, Seed)
Return an integer uniformly in the closed interval [lo, hi].
If lo > hi the bounds are swapped. If lo == hi the bound is
returned without consuming randomness (the seed is still advanced
for determinism).
pub fn random_seed() -> Seed
Construct a seed from the system clock. Useful for ad-hoc local
runs; CI should pin a value via metamon.with_seed(metamon.seed(_)).
pub fn seed(value: Int) -> Seed
Construct a seed from an integer. Negative or out-of-range values are normalised by masking to the 32-bit positive window so the stream stays target-portable.
pub fn split(s: Seed) -> #(Seed, Seed)
Split a seed into two statistically independent seeds. The implementation derives the second seed by xor-ing the first with a constant before stepping, which on a 32-bit LCG produces a stream that does not align with the original — sufficient for shrinking independent generator components without correlation artefacts.