use core::cell::RefCell;

struct RandomState {
    xs64: u64,
}

impl RandomState {
    pub fn generate(&mut self) -> u64 {
        let mut x = self.xs64;
        x ^= x << 13;
        x ^= x >> 7;
        x ^= x << 17;
        self.xs64 = x;
        x
    }

    pub fn seed(&mut self, seed: u64) {
        self.xs64 = seed;
    }
}

#[thread_local]
static STATE: RefCell<RandomState> = RefCell::new(RandomState { xs64: 1234 });

pub fn random_u64() -> u64 {
    STATE.borrow_mut().generate()
}

pub fn seed_u64(seed: u64) {
    STATE.borrow_mut().seed(seed);
}
