Skip to main content

Rng

Struct Rng 

Source
pub struct Rng { /* private fields */ }
Expand description

XorShift64 PRNG — deterministic per seed.

Implementations§

Source§

impl Rng

Source

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.

Source

pub fn next(&mut self) -> u64

Source

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.

Source

pub fn normal(&mut self) -> f32

Standard normal via Box-Muller transform.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.