Skip to main content

Rng

Struct Rng 

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

Minimal seeded pseudo-random number generator.

Uses xorshift64: no heap allocations, no platform-specific dependencies, and produces identical output on wasm32-wasip2 and x86_64.

NOT cryptographically secure — only for reproducible synthetic data.

Implementations§

Source§

impl Rng

Source

pub fn new(seed: u64) -> Self

Create a new RNG seeded with seed.

The seed is mixed with a constant to avoid degenerate all-zero state. Eight warm-up steps eliminate any bias from the initial seed mix.

Source

pub fn next_u64(&mut self) -> u64

Advance state and return the next u64.

Source

pub fn uniform(&mut self, min: f64, max: f64) -> f64

Uniform sample in [min, max).

Source

pub fn normal(&mut self) -> f64

Standard normal sample via Box-Muller transform.

Avoids ln(0) by clamping the uniform draw from below.

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> ByRef<T> for T

Source§

fn by_ref(&self) -> &T

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, 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.
Source§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,