Skip to main content

Module rng

Module rng 

Source
Available on crate feature generators only.
Expand description

Seeded RNG + sampling + combinatorics helpers for the generators.

We drive rand_pcg::Pcg64Mcg through the version-stable rand_core traits (SeedableRng::seed_from_u64 + RngCore::next_u64) and derive all sampling primitives ourselves. This sidesteps rand 0.10’s Rng/RngExt trait split (the probe showed random_range moved to RngExt) and guarantees a fixed, documented f64 construction for cross-build reproducibility.

Functions§

choice_without_replacement
Sample k distinct indices from 0..pool_len (partial Fisher–Yates). Returns them in draw order. Requires k <= pool_len.
comb
Exact binomial coefficient C(n, k) (0 if k > n). Multiplicative form, integer-exact because the running product of k consecutive integers is divisible by k! at each step.
geometric
The geometric sampler (number of trials to first success), clamped to >= 1.
index_to_edge_comb
Map a linear index to the m-combination of 0..n at that index (sorted, strictly increasing). Port of _index_to_edge_comb (uniform.py:457).
index_to_edge_prod
Map a linear index to an m-tuple over 0..n with repetition (product order, last coordinate fastest). Port of _index_to_edge_prod (uniform.py:405).
random_below
A uniform integer in [0, n). Panics via debug-assert if n == 0. Uses modulo reduction (deterministic; slight low-bit bias is acceptable — generator conformance is structural, not sequence-exact).
seeded_rng
Build a Pcg64Mcg from an optional seed. None uses a fixed default seed so that “unseeded” callers are STILL deterministic within a process/build (III.7: non-determinism is a bug — we never reach for entropy).
uniform_f64
A uniform f64 in [0, 1) from 53 bits of the generator (IEEE-754 double mantissa). Fixed construction: (next_u64() >> 11) / 2^53.