pub struct LcgRng { /* private fields */ }Expand description
Minimal LCG (MMIX variant) pseudo-random number generator.
Uses Knuth’s MMIX constants for a full-period 64-bit LCG.
CRITICAL: next_bool() uses bit 32, NOT bit 0 (bit 0 has period 2 in MMIX LCG).
Implementations§
Source§impl LcgRng
impl LcgRng
Sourcepub fn next_bool(&mut self) -> bool
pub fn next_bool(&mut self) -> bool
Return a random bool. Uses bit 32 (NOT bit 0) for better statistical quality.
Sourcepub fn next_normal(&mut self) -> f64
pub fn next_normal(&mut self) -> f64
Return a standard-normal sample via Box-Muller.
Sourcepub fn next_range(&mut self, lo: f64, hi: f64) -> f64
pub fn next_range(&mut self, lo: f64, hi: f64) -> f64
Uniform sample on [lo, hi).
Sourcepub fn sample_categorical(&mut self, probs: &[f64]) -> usize
pub fn sample_categorical(&mut self, probs: &[f64]) -> usize
Sample a categorical index given a probability vector. Probabilities are expected to sum to ~1; if the sum is short due to rounding, the last index is returned.
Sourcepub fn next_usize(&mut self, n: usize) -> usize
pub fn next_usize(&mut self, n: usize) -> usize
Return a random usize in [0, n). Returns 0 if n == 0.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for LcgRng
impl RefUnwindSafe for LcgRng
impl Send for LcgRng
impl Sync for LcgRng
impl Unpin for LcgRng
impl UnsafeUnpin for LcgRng
impl UnwindSafe for LcgRng
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more