pub struct Rng { /* private fields */ }Expand description
XorShift64 PRNG — deterministic per seed.
Implementations§
Source§impl Rng
impl Rng
Sourcepub fn new(seed: u64) -> Self
pub fn new(seed: u64) -> Self
Construct from a 64-bit seed.
Applies one round of SplitMix64 mixing to decorrelate low-entropy seeds
(Issue 296). Without this, small seeds like 0, 1, 2, 42 keep the
XorShift64 state small enough that the first next() has zero upper 24
bits, so uniform() returns exactly 0.0 — which sits on the left
boundary of any inverse-CDF sampler and deterministically selects the
first token with nonzero mass. SplitMix64 is the standard remedy for
XorShift “small seed” weakness: it diffuses any input (including 0)
into a well-distributed 64-bit state in O(1).
Cost: ~3 mul/shift per Rng::new. Negligible — new() is called once
per inference/training session, not in hot loops.
pub fn next(&mut self) -> u64
Sourcepub fn uniform(&mut self) -> f32
pub fn uniform(&mut self) -> f32
Uniform [0, 1) — 24 bits of entropy (full f32 mantissa precision).
Note: returns a value in the half-open interval [0, 1). The exact bound
0.0 is reachable in principle (24 zero bits) but, after the SplitMix64
seed mixing in Rng::new, is no longer the deterministic first draw for
small seeds. Samplers that require a strictly positive variate should
still redraw on r == 0.0 as a defensive belt — see Issue 296.
Auto Trait Implementations§
impl Freeze for Rng
impl RefUnwindSafe for Rng
impl Send for Rng
impl Sync for Rng
impl Unpin for Rng
impl UnsafeUnpin for Rng
impl UnwindSafe for Rng
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more