summaryrefslogtreecommitdiffstats
path: root/src/transport
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/sim.rs35
1 files changed, 3 insertions, 32 deletions
diff --git a/src/transport/sim.rs b/src/transport/sim.rs
index 1556d69..ce5977f 100644
--- a/src/transport/sim.rs
+++ b/src/transport/sim.rs
@@ -26,6 +26,7 @@ use tracing::{debug, warn};
use super::mycelium::{decode_message, encode_message};
use super::{EncodedMessage, MessageHandler, MessageKind, ParsedMessage, Transport};
+use crate::testrand::Rng;
/// How one direction of a link behaves.
#[derive(Clone, Debug)]
@@ -72,7 +73,7 @@ pub(crate) struct NetCounts {
}
struct NetInner {
- rng: SplitMix64,
+ rng: Rng,
default_link: LinkParams,
links: HashMap<(String, String), LinkParams>,
down: HashSet<String>,
@@ -90,7 +91,7 @@ impl SimNet {
pub(crate) fn new(seed: u64) -> Self {
Self {
inner: Arc::new(Mutex::new(NetInner {
- rng: SplitMix64(seed),
+ rng: Rng::new(seed),
default_link: LinkParams::default(),
links: HashMap::new(),
down: HashSet::new(),
@@ -306,36 +307,6 @@ impl Transport for SimTransport {
}
}
-/// A small, seedable generator (SplitMix64): enough for network decisions, and no
-/// dependency.
-struct SplitMix64(u64);
-
-impl SplitMix64 {
- fn next_u64(&mut self) -> u64 {
- self.0 = self.0.wrapping_add(0x9e37_79b9_7f4a_7c15);
- let mut z = self.0;
- z = (z ^ (z >> 30)).wrapping_mul(0xbf58_476d_1ce4_e5b9);
- z = (z ^ (z >> 27)).wrapping_mul(0x94d0_49bb_1331_11eb);
- z ^ (z >> 31)
- }
-
- /// Uniform in [0, 1).
- fn next_f64(&mut self) -> f64 {
- (self.next_u64() >> 11) as f64 / (1_u64 << 53) as f64
- }
-
- fn chance(&mut self, probability: f64) -> bool {
- probability > 0.0 && self.next_f64() < probability
- }
-
- fn duration_in(&mut self, (min, max): (Duration, Duration)) -> Duration {
- if max <= min {
- return min;
- }
- min + (max - min).mul_f64(self.next_f64())
- }
-}
-
#[cfg(test)]
mod tests {
use super::*;