diff --git a/Cargo.toml b/Cargo.toml index c7c406c0..63b445a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ log = "0.4.5" parking_lot = "0.11.0" rustc-hash = "1.0" smallvec = "1.0.0" -rand = { version = "0.7", features = [ "small_rng" ], default-features = false } +oorandom = "11" salsa-macros = { version = "0.15.0", path = "components/salsa-macros" } diff --git a/src/lru.rs b/src/lru.rs index 22a10e97..e72f923d 100644 --- a/src/lru.rs +++ b/src/lru.rs @@ -1,7 +1,5 @@ use parking_lot::Mutex; -use rand::rngs::SmallRng; -use rand::Rng; -use rand::SeedableRng; +use oorandom::Rand64; use std::fmt::Debug; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; @@ -33,7 +31,7 @@ struct LruData { end_red_zone: usize, end_yellow_zone: usize, end_green_zone: usize, - rng: SmallRng, + rng: Rand64, entries: Vec>, } @@ -141,7 +139,7 @@ where Self::with_rng(rng_with_seed(seed_str)) } - fn with_rng(rng: SmallRng) -> Self { + fn with_rng(rng: Rand64) -> Self { LruData { end_yellow_zone: 0, end_green_zone: 0, @@ -287,7 +285,7 @@ where fn pick_index(&mut self, zone: std::ops::Range) -> usize { let end_index = std::cmp::min(zone.end, self.entries.len()); - self.rng.gen_range(zone.start, end_index) + self.rng.rand_range(zone.start as u64 .. end_index as u64) as usize } } @@ -317,12 +315,12 @@ impl LruIndex { } } -fn rng_with_seed(seed_str: &str) -> SmallRng { +fn rng_with_seed(seed_str: &str) -> Rand64 { let mut seed: [u8; 16] = [0; 16]; for (i, &b) in seed_str.as_bytes().iter().take(16).enumerate() { seed[i] = b; } - SmallRng::from_seed(seed) + Rand64::new(u128::from_le_bytes(seed)) } // A note on ordering: