std::randomSeedable pseudo-random number generation.
Backed by a CPython-compatible MT19937 Mersenne Twister implemented in
hew-runtime/src/random.rs. State is thread-local — one generator per
thread. A fixed seed produces a deterministic, reproducible sequence that
matches CPython's random module output for the same seed.
fn main() {
random.seed(42);
let r = random.random(); // ≈ 0.6394267984578837
let n = random.randint(0, 10);
}
seedSeed the PRNG so subsequent calls produce a deterministic sequence.
The seed is reduced to its low 32 bits and passed to CPython's
init_by_array. Calling seed with the same value always produces
the same stream.
randomReturn a random float in [0.0, 1.0) with 53-bit precision.
Uses CPython's random() algorithm (two 27/26-bit MT words combined).
gaussReturn a random float drawn from a Gaussian (normal) distribution
with the given mean and sigma (standard deviation).
Uses the Box-Muller method with spare-value caching, matching
CPython's random.gauss implementation.
randintReturn a random integer in the half-open range [lo, hi).
Returns lo when hi <= lo.
shuffleShuffle a Vec<i64> in-place using Fisher-Yates.
Matches CPython's random.shuffle output for the same seed.
choicesWeighted choice by bisecting cumulative weights. Returns the chosen index.
weights is a Vec<f64> of cumulative weights (each entry is the sum of
all weights up to and including that index), total is the grand total,
and n is reserved for future multi-sample use (pass 1).