Skip to main content

DetRng

Struct DetRng 

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

A deterministic pseudo-random number generator.

Uses a 64-bit LCG (Linear Congruential Generator) with PCG constants. Same seed always produces the same sequence — this is the foundation of Vortex’s reproducibility guarantee.

Implementations§

Source§

impl DetRng

Source

pub fn new(seed: u64) -> Self

Create a new RNG with the given seed.

Source

pub fn derive(master_seed: u64, domain: &str) -> Self

Create a child RNG for a subsystem by mixing the master seed with a domain tag.

This ensures different subsystems (network, storage, clock) get independent but deterministic random streams from the same master seed.

let master = 42u64;
let net_rng = DetRng::derive(master, "network");
let disk_rng = DetRng::derive(master, "storage");
// net_rng and disk_rng produce different sequences
Source

pub fn next_u64(&mut self) -> u64

Advance the RNG state and return the next raw u64.

Source

pub fn next_f64(&mut self) -> f64

Return a random f64 in [0.0, 1.0).

Source

pub fn next_u64_below(&mut self, max: u64) -> u64

Return a random u64 in [0, max) (exclusive upper bound).

Source

pub fn next_u64_range(&mut self, min: u64, max: u64) -> u64

Return a random u64 in [min, max] (inclusive both bounds).

Source

pub fn chance(&mut self, probability: f64) -> bool

Return true with the given probability [0.0, 1.0].

Source

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

Shuffle a slice in-place (Fisher-Yates).

Source

pub fn state(&self) -> u64

Get the current internal state (for debugging/logging).

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.