pub(crate) struct SimpleRng(u64);
impl SimpleRng {
pub fn new(seed: u64) -> Self {
Self(seed)
}
pub fn from_time() -> Self {
let seed = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_nanos() as u64;
Self::new(seed)
}
pub fn next_u64(&mut self) -> u64 {
self.0 = self
.0
.wrapping_mul(6364136223846793005)
.wrapping_add(1442695040888963407);
self.0
}
pub fn next_usize(&mut self, bound: usize) -> usize {
(self.next_u64() % bound as u64) as usize
}
pub fn shuffle<T>(&mut self, slice: &mut [T]) {
for i in (1..slice.len()).rev() {
let j = self.next_usize(i + 1);
slice.swap(i, j);
}
}
}