std/numeric/random
std/random — pseudorandom number generation.
The API is the global RNG: nextI32 / nextI64 / nextF64 /nextBool / nextRange consume from a process-wide xoshiro256
state seeded once at first use from the OS CSPRNG, falling back to
the wall clock. Not the monotonic clock: its origin is set by the
first read, so it would yield near-zero and near-constant across
runs — and this seed keys HashMap bucket order.
Free functions
| Type | Method and description |
|---|---|
| seed(seedValue : i64) : void Reseeds the process-wide xoshiro256 stream so subsequent draws are reproducible. Pass a fixed value for deterministic test runs. |
| nextI32() : i32 Next uniform i32 over the full i32 range. |
| nextI64() : i64 Next uniform i64 over the full i64 range. |
| nextF64() : f64 Next uniform f64 in [0.0, 1.0). |
| nextBool() : bool Next bool, true or false with equal probability. |
| nextRangeI32(min : i32, max : i32) : i32 Next uniform i32 in the half-open range [min, max). Returns minunchanged when max <= min.Uniform, not modulo-derived: a draw that would give one residue an extra chance is discarded and redrawn, so every value in the interval has the same probability whatever the span. |
| nextRangeI64(min : i64, max : i64) : i64 Next uniform i64 in the half-open range [min, max). Returns minunchanged when max <= min. |
Method detail
#seed
Reseeds the process-wide xoshiro256 stream so subsequent draws are
reproducible. Pass a fixed value for deterministic test runs.
seedValue the new seed for the xoshiro256 stream#nextI32
Next uniform i32 over the full i32 range.
#nextI64
Next uniform i64 over the full i64 range.
#nextF64
Next uniform f64 in [0.0, 1.0).
#nextBool
Next bool, true or false with equal probability.
#nextRangeI32
Next uniform i32 in the half-open range [min, max). Returns min
unchanged when max <= min.
Uniform, not modulo-derived: a draw that would give one residue an extra
chance is discarded and redrawn, so every value in the interval has the
same probability whatever the span.
min inclusive lower boundmax exclusive upper bound#nextRangeI64
Next uniform i64 in the half-open range [min, max). Returns min
unchanged when max <= min.
min inclusive lower boundmax exclusive upper boundC class Random
Same process-wide stream as the free functions above; the
class exists to make Random::nextI32() reachable without an
explicit use std::numeric::random::nextI32. There is a single
process-wide stream rather than per-instance RNG state.
Methods
| Type | Method and description |
|---|---|
| seed(seedValue : i64) : void Reseeds the shared stream — see the free fn seed. |
| nextI32() : i32 Next uniform i32 over the full range — see nextI32. |
| nextI64() : i64 Next uniform i64 over the full range — see nextI64. |
| nextF64() : f64 Next uniform f64 in [0.0, 1.0) — see nextF64. |
| nextBool() : bool Next bool, 50/50 — see nextBool. |
| nextRangeI32(min : i32, max : i32) : i32 Next uniform i32 in [min, max) — see nextRangeI32. |
| nextRangeI64(min : i64, max : i64) : i64 Next uniform i64 in [min, max) — see nextRangeI64. |
Method detail
#seed
Reseeds the shared stream — see the free fn seed.
seedValue the new seed value#nextI32
Next uniform i32 over the full range — see nextI32.
#nextI64
Next uniform i64 over the full range — see nextI64.
#nextF64
Next uniform f64 in [0.0, 1.0) — see nextF64.
#nextBool
Next bool, 50/50 — see nextBool.
#nextRangeI32
Next uniform i32 in [min, max) — see nextRangeI32.
min inclusive lower boundmax exclusive upper bound; max <= min yields min#nextRangeI64
Next uniform i64 in [min, max) — see nextRangeI64.
min inclusive lower boundmax exclusive upper bound; max <= min yields min