use wrapn::Wrap;
use crate::_internal::impl_seed;
use crate::rng::Rng64;
use crate::rng64::SplitMix64;
#[repr(C)]
pub struct Xorshift64 {
a: Wrap<u64>,
}
impl Xorshift64 {
pub fn new(seed: u64) -> Self {
let mut seedgen = SplitMix64::new(seed);
Self {
a: seedgen.nextu().into(),
}
}
}
impl_seed!(Xorshift64, 64);
impl Rng64 for Xorshift64 {
#[inline]
fn nextu(&mut self) -> u64 {
let mut x = self.a;
x ^= x << 13;
x ^= x >> 7;
x ^= x << 17;
self.a = x;
x.value()
}
}
#[cfg(test)]
mod tests {
use super::*;
crate::safe_test!(Xorshift64);
}