#[allow(clippy::unused_trait_names)]
#[allow(unused_imports)]
use crate::traits::{CoreRNG, FloatRNG, SeekableRNG};
#[allow(unused_imports)]
use crate::wyrand::WyRand;
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct Lehmer64 {
state: u128,
}
impl Lehmer64 {
const MULTIPLIER: u128 = 0xDA94_2042_E4DD_58B5;
pub const WARMUP_ITERATIONS: usize = 4;
pub const DEFAULT_SEED: u64 = 0x2FB6_A490_3F74_5A36;
#[inline]
#[must_use]
pub fn new_without_warmup(seed: u64) -> Self {
Self {
state: u128::from(seed),
}
}
}
impl CoreRNG for Lehmer64 {
#[inline]
fn new(seed: u64) -> Self {
let mut generator = Self::new_without_warmup(seed);
for _ in 0..Self::WARMUP_ITERATIONS {
let _ = generator.next();
}
generator
}
#[inline]
#[allow(clippy::cast_possible_truncation)]
fn next(&mut self) -> u64 {
self.state = self.state.wrapping_mul(Self::MULTIPLIER);
(self.state >> 64) as u64
}
}
#[cfg(feature = "float")]
impl FloatRNG for Lehmer64 {}
impl Default for Lehmer64 {
fn default() -> Self {
Self::new(Self::DEFAULT_SEED)
}
}