criterion/stats/
rand_util.rs

1use oorandom::Rand64;
2use std::cell::RefCell;
3use std::time::{SystemTime, UNIX_EPOCH};
4
5pub type Rng = Rand64;
6
7thread_local! {
8    static SEED_RAND: RefCell<Rand64> = RefCell::new(Rand64::new(
9        SystemTime::now().duration_since(UNIX_EPOCH)
10            .expect("Time went backwards")
11            .as_millis()
12    ));
13}
14
15pub fn new_rng() -> Rng {
16    SEED_RAND.with(|r| {
17        let mut r = r.borrow_mut();
18        let seed = ((r.rand_u64() as u128) << 64) | (r.rand_u64() as u128);
19        Rand64::new(seed)
20    })
21}