21 lines
574 B
Rust
21 lines
574 B
Rust
pub fn pcg64(state: &mut u128) -> u64 {
|
|
let mut x = *state;
|
|
pcg64_iterstate(state);
|
|
let count = (x >> (128 - 6)) as u32; // Highest 6 bits
|
|
x ^= x >> 35;
|
|
((x >> 58) as u64).rotate_right(count)
|
|
}
|
|
|
|
fn pcg64_iterstate(state: &mut u128) {
|
|
const MULTIPLIER: u128 = 0xde92a69f6e2f9f25fd0d90f576075fbd;
|
|
const INCREMENT: u128 = 621;
|
|
*state = state.wrapping_mul(MULTIPLIER).wrapping_add(INCREMENT);
|
|
}
|
|
|
|
pub fn pcg64_seed(state: &mut u128, bytes: &[u8]) {
|
|
for byte in bytes {
|
|
*state = (*state ^ *byte as u128).rotate_right(8);
|
|
}
|
|
pcg64_iterstate(state);
|
|
}
|