#[derive(Clone, Copy, Debug)]
pub struct Xorshift64 {
state: u64,
}
impl Xorshift64 {
const SEED_FALLBACK: u64 = 0x9E37_79B9_7F4A_7C15;
#[inline]
pub const fn new(seed: u64) -> Self {
let state = if seed == 0 { Self::SEED_FALLBACK } else { seed };
Self { state }
}
#[inline]
pub fn next_u64(&mut self) -> u64 {
let mut x = self.state;
x ^= x >> 12;
x ^= x << 25;
x ^= x >> 27;
self.state = x;
x.wrapping_mul(0x2545_F491_4F6C_DD1D)
}
#[inline]
pub fn next_unit_f64(&mut self) -> f64 {
let bits = self.next_u64() >> 11;
bits as f64 * (1.0 / (1u64 << 53) as f64)
}
}