Axle v0.22.0
Package

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

TypeMethod and description
void
seed(seedValue : i64) : void Reseeds the process-wide xoshiro256 stream so subsequent draws are
reproducible. Pass a fixed value for deterministic test runs.
i32
nextI32() : i32 Next uniform i32 over the full i32 range.
i64
nextI64() : i64 Next uniform i64 over the full i64 range.
f64
nextF64() : f64 Next uniform f64 in [0.0, 1.0).
bool
nextBool() : bool Next bool, true or false with equal probability.
i32
nextRangeI32(min : i32, max : i32) : i32 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.
i64
nextRangeI64(min : i64, max : i64) : i64 Next uniform i64 in the half-open range [min, max). Returns min
unchanged when max <= min.

Method detail

#seed

seed(seedValue : i64) : void

Reseeds the process-wide xoshiro256 stream so subsequent draws are
reproducible. Pass a fixed value for deterministic test runs.

Parameters
seedValue the new seed for the xoshiro256 stream

#nextI32

nextI32() : i32

Next uniform i32 over the full i32 range.

#nextI64

nextI64() : i64

Next uniform i64 over the full i64 range.

#nextF64

nextF64() : f64

Next uniform f64 in [0.0, 1.0).

#nextBool

nextBool() : bool

Next bool, true or false with equal probability.

#nextRangeI32

nextRangeI32(min : i32, max : i32) : i32

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.

Parameters
min inclusive lower bound
max exclusive upper bound

#nextRangeI64

nextRangeI64(min : i64, max : i64) : i64

Next uniform i64 in the half-open range [min, max). Returns min
unchanged when max <= min.

Parameters
min inclusive lower bound
max exclusive upper bound

C 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

TypeMethod and description
void
seed(seedValue : i64) : void Reseeds the shared stream — see the free fn seed.
i32
nextI32() : i32 Next uniform i32 over the full range — see nextI32.
i64
nextI64() : i64 Next uniform i64 over the full range — see nextI64.
f64
nextF64() : f64 Next uniform f64 in [0.0, 1.0) — see nextF64.
bool
nextBool() : bool Next bool, 50/50 — see nextBool.
i32
nextRangeI32(min : i32, max : i32) : i32 Next uniform i32 in [min, max) — see nextRangeI32.
i64
nextRangeI64(min : i64, max : i64) : i64 Next uniform i64 in [min, max) — see nextRangeI64.

Method detail

#seed

seed(seedValue : i64) : void

Reseeds the shared stream — see the free fn seed.

Parameters
seedValue the new seed value

#nextI32

nextI32() : i32

Next uniform i32 over the full range — see nextI32.

#nextI64

nextI64() : i64

Next uniform i64 over the full range — see nextI64.

#nextF64

nextF64() : f64

Next uniform f64 in [0.0, 1.0) — see nextF64.

#nextBool

nextBool() : bool

Next bool, 50/50 — see nextBool.

#nextRangeI32

nextRangeI32(min : i32, max : i32) : i32

Next uniform i32 in [min, max) — see nextRangeI32.

Parameters
min inclusive lower bound
max exclusive upper bound; max <= min yields min

#nextRangeI64

nextRangeI64(min : i64, max : i64) : i64

Next uniform i64 in [min, max) — see nextRangeI64.

Parameters
min inclusive lower bound
max exclusive upper bound; max <= min yields min