Skip to main content

SeededRng

Struct SeededRng 

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

A deterministic, snapshot/restore-able RNG for record-and-replay.

Backed by rand_chacha::ChaCha20Rng. Given the same seed and the same number of draws, every instance produces the identical u64 sequence; snapshot + restore reproduces the remaining draws exactly, and split yields an independent substream that does not perturb the parent.

Implementations§

Source§

impl SeededRng

Source

pub fn from_seed(seed: u64) -> Self

Construct from a 64-bit seed. The full 256-bit ChaCha key is derived by zero-extending the seed (this is ChaCha20Rng::seed_from_u64).

Source

pub fn next_u64(&mut self) -> u64

Draw the next u64 from the stream, advancing position.

Source

pub fn snapshot(&self) -> RngState

Capture the current position so it can be restored later to reproduce the identical subsequent draw sequence.

Source

pub fn restore(state: RngState) -> Self

Rebuild a SeededRng positioned exactly where state was taken.

Source

pub fn split(&mut self) -> Self

Fork an independent substream. The child shares the seed but selects a distinct ChaCha stream, so its draws never overlap the parent’s and splitting does not consume any of the parent’s keystream.

Auto Trait Implementations§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,