From ed2bd527e86581ea0f65903cc9bf690a0f84e3a1 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Tue, 2 Jul 2019 06:34:37 -0400 Subject: [PATCH] use a fixed seed --- src/lru.rs | 15 +++++---------- src/lru/test.rs | 3 +-- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/lru.rs b/src/lru.rs index e6c29e8a..22a10e97 100644 --- a/src/lru.rs +++ b/src/lru.rs @@ -1,6 +1,5 @@ use parking_lot::Mutex; use rand::rngs::SmallRng; -use rand::FromEntropy; use rand::Rng; use rand::SeedableRng; use std::fmt::Debug; @@ -58,16 +57,17 @@ where } } +// We always use a fixed seed for our randomness so that we have +// predictable results. +const LRU_SEED: &str = "Hello, Rustaceans"; + impl Lru where Node: LruNode, { /// Creates a new LRU list where LRU caching is disabled. pub fn new() -> Self { - Lru { - green_zone: AtomicUsize::new(0), - data: Mutex::new(LruData::new()), - } + Self::with_seed(LRU_SEED) } #[cfg_attr(not(test), allow(dead_code))] @@ -137,11 +137,6 @@ impl LruData where Node: LruNode, { - fn new() -> Self { - Self::with_rng(SmallRng::from_entropy()) - } - - #[cfg_attr(not(test), allow(dead_code))] fn with_seed(seed_str: &str) -> Self { Self::with_rng(rng_with_seed(seed_str)) } diff --git a/src/lru/test.rs b/src/lru/test.rs index 8f48d5cb..d77903a5 100644 --- a/src/lru/test.rs +++ b/src/lru/test.rs @@ -25,7 +25,6 @@ impl LruNode for TestNode { } } -const LRU_SEED: &str = "Hello, Rustaceans"; const PICK_SEED: &str = "Wippity WIP"; /// Randomly requests nodes and compares the performance of a @@ -48,7 +47,7 @@ fn compare( // it. When the capacity is exceed, we can pop the oldest. let mut oracle = LinkedHashMap::new(); - let lru = Lru::with_seed(LRU_SEED); + let lru = Lru::with_seed(super::LRU_SEED); lru.set_lru_capacity(capacity); let nodes: Vec<_> = (0..num_nodes).map(|i| TestNode::new(i)).collect();