//! A seeded random — xorshift64*, which is enough for invented data and is//! the same on every machine. Implements the tools crate's `Random` so a//! handler's uuids come off the seed too.usecrate::random::Random;use std::sync::Mutex;#[derive(Debug)]pubstructSeededRandom(Mutex<u64>);implSeededRandom {pubfn new(seed: u64) -> SeededRandom {// A zero state never leaves zero; fold the seed with a constant.SeededRandom(Mutex::new(seed ^ 0x9E37_79B9_7F4A_7C15 | 1)) }pubfn next_u64(&self) -> u64 {letmut state = self.0.lock().unwrap_or_else(|poisoned| poisoned.into_inner());letmut x = *state; x ^= x >> 12; x ^= x << 25; x ^= x >> 27; *state = x; x.wrapping_mul(0x2545_F491_4F6C_DD1D) }/// `0..n`.pubfn below(&self, n: usize) -> usize {if n == 0 {return0; } (self.next_u64() % n as u64) as usize }/// `lo..=hi`.pubfn between(&self, lo: i64, hi: i64) -> i64 {if hi <= lo {return lo; } lo + (self.next_u64() % (hi - lo + 1) as u64) as i64 }pubfn chance(&self, per_cent: u64) -> bool {self.next_u64() % 100 < per_cent }pubfn pick<'a, T>(&self, items: &'a [T]) -> &'a T { &items[self.below(items.len())] }}implRandomforSeededRandom {fn fill(&self, bytes: &mut [u8]) {for chunk in bytes.chunks_mut(8) {let word = self.next_u64().to_le_bytes(); chunk.copy_from_slice(&word[..chunk.len()]); } }}