TreeRng

Struct TreeRng 

Source
pub struct TreeRng<Rng = Pcg64Mcg> { /* private fields */ }
Expand description

A hierarchical pseudo-random number generator (PRNG).

TreeRng organizes RNGs into a tree structure, allowing you to create independent child RNGs from a parent RNG. This ensures stability and reproducibility in random number generation across code changes.

§Type Parameters

  • Rng: A PRNG type that implements both SeedableRng and RngCore.

Implementations§

Source§

impl<Rng: SeedableRng + RngCore> TreeRng<Rng>

Source

pub fn new(seed: u64) -> TreeRng<Rng>

Creates a new TreeRng initialized with the given seed.

Source

pub fn child(&self, index: u64) -> TreeRng<Rng>

Creates a child TreeRng from this RNG using the given index.

Source

pub fn seed(&self) -> u64

Returns the seed used to initialize this RNG.

Trait Implementations§

Source§

impl<Rng: RngCore> RngCore for TreeRng<Rng>

Source§

fn next_u32(&mut self) -> u32

Return the next random u32. Read more
Source§

fn next_u64(&mut self) -> u64

Return the next random u64. Read more
Source§

fn fill_bytes(&mut self, dest: &mut [u8])

Fill dest with random data. Read more

Auto Trait Implementations§

§

impl<Rng> Freeze for TreeRng<Rng>
where Rng: Freeze,

§

impl<Rng> RefUnwindSafe for TreeRng<Rng>
where Rng: RefUnwindSafe,

§

impl<Rng> Send for TreeRng<Rng>
where Rng: Send,

§

impl<Rng> Sync for TreeRng<Rng>
where Rng: Sync,

§

impl<Rng> Unpin for TreeRng<Rng>
where Rng: Unpin,

§

impl<Rng> UnwindSafe for TreeRng<Rng>
where Rng: UnwindSafe,

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, 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<R> TryRngCore for R
where R: RngCore + ?Sized,

Source§

type Error = Infallible

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

fn try_next_u32(&mut self) -> Result<u32, <R as TryRngCore>::Error>

Return the next random u32.
Source§

fn try_next_u64(&mut self) -> Result<u64, <R as TryRngCore>::Error>

Return the next random u64.
Source§

fn try_fill_bytes( &mut self, dst: &mut [u8], ) -> Result<(), <R as TryRngCore>::Error>

Fill dest entirely with random data.
Source§

fn unwrap_err(self) -> UnwrapErr<Self>
where Self: Sized,

Wrap RNG with the UnwrapErr wrapper.
Source§

fn unwrap_mut(&mut self) -> UnwrapMut<'_, Self>

Wrap RNG with the UnwrapMut wrapper.