use super::RandomBackend;
#[derive(Clone, Debug)]
pub struct LCG {
state: u64,
}
impl LCG {
pub fn new(seed: u64) -> Self {
Self { state: seed }
}
}
impl RandomBackend for LCG {
fn next_u64(&mut self) -> u64 {
const MULTIPLIER: u64 = 6364136223846793005;
const INCREMENT: u64 = 1442695040888963407;
self.state = self.state.wrapping_mul(MULTIPLIER).wrapping_add(INCREMENT);
self.state
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn lcg_basic_progression() {
let mut lcg = LCG::new(12345);
let a = lcg.next_u64();
let b = lcg.next_u64();
assert_ne!(a, b);
}
}