use rand_distr::{
Distribution as _,
Normal,
SkewNormal,
};
use std::time::Duration;
pub fn normal_distribution(
mean: f64,
std_dev: f64,
max: f64,
) -> Option<impl FnMut() -> Option<Duration> + Send + Sync + 'static> {
let normal = Normal::new(mean, std_dev).unwrap(); Some(move || {
let latency = normal.sample(&mut rand::rng()).clamp(0.0, max) as u64;
(latency > 0).then(|| std::time::Duration::from_millis(latency))
})
}
pub fn skewed_distribution(
location: f64,
scale: f64,
shape: f64,
max: f64,
) -> Option<impl FnMut() -> Option<Duration> + Send + Sync + 'static> {
let skew_normal = SkewNormal::new(location, scale, shape).unwrap(); Some(move || {
let latency = skew_normal.sample(&mut rand::rng()).clamp(0.0, max) as u64;
(latency > 0).then(|| std::time::Duration::from_millis(latency))
})
}