veloren/world/src/util/seed_expan.rs

17 lines
402 B
Rust
Raw Normal View History

2019-08-06 00:03:51 +00:00
/// Simple non-cryptographic diffusion function.
pub fn diffuse(mut x: u32) -> u32 {
x ^= 2281701376;
x = x.rotate_left(7);
x.wrapping_mul(0x811c9dc5)
2019-08-05 16:46:28 +00:00
}
2019-08-06 00:03:51 +00:00
/// Expand a 32 bit seed into a 32 byte RNG state.
pub fn rng_state(mut x: u32) -> [u8; 32] {
let mut r: [u32; 8] = [0; 8];
for s in &mut r {
x = diffuse(x);
*s = x;
2019-08-05 16:46:28 +00:00
}
unsafe { std::mem::transmute(r) }
}