pub fn parallel_normal_sample(
n: usize,
mean: f64,
std_dev: f64,
seed: Option<u64>,
) -> StatsResult<Vec<f64>>Expand description
Generate n independent samples from N(mean, std_dev²) using parallel
threads (via Rayon) and per-thread SIMD Box-Muller kernels.
The work is split into num_cpus chunks. Each chunk receives a
deterministic seed derived from the user-supplied seed and the chunk
index, making the output fully reproducible when seed is provided.
§Arguments
n— Total number of samples to generate.mean— Location parameter of the Normal distribution.std_dev— Scale parameter (must be positive).seed— Optional base RNG seed for reproducibility.
§Errors
Returns StatsError::InvalidArgument when n == 0 or std_dev <= 0.
§Examples
use scirs2_stats::simd_sampling::parallel_normal_sample;
let samples = parallel_normal_sample(10_000, 5.0_f64, 2.0_f64, Some(42))
.expect("parallel sampling failed");
assert_eq!(samples.len(), 10_000);
let mean: f64 = samples.iter().sum::<f64>() / 10_000.0;
assert!((mean - 5.0).abs() < 0.2, "empirical mean {mean} too far from 5.0");