pub struct SimRng { /* private fields */ }Expand description
Deterministic, reproducible random number generator.
Based on PCG (Permuted Congruential Generator) which provides:
- Excellent statistical properties
- Fast generation
- Predictable sequences from seed
- Independent streams via partitioning
Implementations§
Source§impl SimRng
impl SimRng
Sourcepub const fn master_seed(&self) -> u64
pub const fn master_seed(&self) -> u64
Get the master seed.
Sourcepub fn partition(&mut self, n: usize) -> Vec<Self>
pub fn partition(&mut self, n: usize) -> Vec<Self>
Create partitioned RNGs for parallel execution.
Each partition gets an independent stream derived from the master seed, ensuring reproducibility regardless of execution order.
§Example
use simular::engine::rng::SimRng;
let mut rng = SimRng::new(42);
let partitions = rng.partition(4);
assert_eq!(partitions.len(), 4);Sourcepub fn gen_range_f64(&mut self, min: f64, max: f64) -> f64
pub fn gen_range_f64(&mut self, min: f64, max: f64) -> f64
Sourcepub fn gen_standard_normal(&mut self) -> f64
pub fn gen_standard_normal(&mut self) -> f64
Generate a standard normal sample using Box-Muller transform.
Sourcepub fn gen_normal(&mut self, mean: f64, std: f64) -> f64
pub fn gen_normal(&mut self, mean: f64, std: f64) -> f64
Generate a normal sample with given mean and std.
Sourcepub fn state_bytes(&self) -> Vec<u8> ⓘ
pub fn state_bytes(&self) -> Vec<u8> ⓘ
Get RNG state as bytes for hashing (audit logging).
Returns a deterministic byte representation of the RNG state.
Sourcepub fn save_state(&self) -> RngState
pub fn save_state(&self) -> RngState
Save RNG state for checkpoint.
Note: PCG internal state is not directly serializable, so we save enough information to recreate the RNG at the same point in the stream.
Sourcepub fn restore_state(&mut self, state: &RngState) -> Result<(), RngRestoreError>
pub fn restore_state(&mut self, state: &RngState) -> Result<(), RngRestoreError>
Trait Implementations§
Source§impl<'de> Deserialize<'de> for SimRng
impl<'de> Deserialize<'de> for SimRng
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for SimRng
impl RefUnwindSafe for SimRng
impl Send for SimRng
impl Sync for SimRng
impl Unpin for SimRng
impl UnsafeUnpin for SimRng
impl UnwindSafe for SimRng
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more