Skip to main content

deterministic_rng

Function deterministic_rng 

Source
pub fn deterministic_rng(seed: u64) -> StdRng
Expand description

Returns a seeded StdRng for reproducible Monte-Carlo / simulation tests.

Per rules/global_rules.md §Numerical Discipline, every Monte-Carlo and simulation test must seed deterministically so that an upstream arithmetic-precision shift cannot flip an assertion by luck. Use this helper instead of rand::rng() / rand::random() inside any #[cfg(test)] block whose expected values depend on the sample stream.

use optionstratlib_core::utils::deterministic_rng;
use rand::RngExt;
let mut rng = deterministic_rng(42);
let _ = rng.random::<u64>();