Skip to main content

Rng

Struct Rng 

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

Pseudo-random number generator (xoshiro256**) with fixed seed.

Implementations§

Source§

impl Rng

Source

pub fn new(seed: u64) -> Rng

Creates an RNG from seed via SplitMix64 mixing.

Source

pub fn next_u64(&mut self) -> u64

Generates the next 64-bit integer.

Source

pub fn next_f64(&mut self) -> f64

Generates a uniform float in [0, 1).

Source

pub fn uniform(&mut self, lo: f64, hi: f64) -> f64

Generates a uniform float in [lo, hi).

Source

pub fn next_usize(&mut self, n: usize) -> usize

Generates a uniform index in [0, n).

Source

pub fn normal(&mut self) -> f64

Generates a standard normal sample (Box-Muller).

Source

pub fn normal_params(&mut self, mu: f64, sigma: f64) -> f64

Generates a normal sample with parameters (mu, sigma).

Source

pub fn fill_uniform(&mut self, buf: &mut [f64])

Fills buf with uniform values in [0, 1).

Source

pub fn fill_normal(&mut self, buf: &mut [f64])

Fills buf with standard normal values.

Source

pub fn shuffle<T>(&mut self, data: &mut [T])

Shuffles data in place (Fisher-Yates).

Source

pub fn sample_uniform(&mut self, n: usize, lo: f64, hi: f64) -> Vec<f64>

Generates n uniform samples in [lo, hi).

Source

pub fn sample_normal(&mut self, n: usize, mu: f64, sigma: f64) -> Vec<f64>

Generates n normal samples with parameters (mu, sigma).

Trait Implementations§

Source§

impl Clone for Rng

Source§

fn clone(&self) -> Rng

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Rng

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.