Skip to content

Commit

Permalink
Use wyrand final v4.2 constants for gen_u64()
Browse files Browse the repository at this point in the history
  • Loading branch information
Bluefinger authored and notgull committed Apr 27, 2024
1 parent 63175fa commit 351a708
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,14 @@ impl Rng {
/// Generates a random `u64`.
#[inline]
fn gen_u64(&mut self) -> u64 {
let s = self.0.wrapping_add(0xA0761D6478BD642F);
// Constants for WyRand taken from: https://github.com/wangyi-fudan/wyhash/blob/master/wyhash.h#L151
// Updated for the final v4.2 implementation with improved constants for better entropy output.
const WY_CONST_0: u64 = 0x2d35_8dcc_aa6c_78a5;
const WY_CONST_1: u64 = 0x8bb8_4b93_962e_acc9;

let s = self.0.wrapping_add(WY_CONST_0);
self.0 = s;
let t = u128::from(s) * u128::from(s ^ 0xE7037ED1A0B428DB);
let t = u128::from(s) * u128::from(s ^ WY_CONST_1);
(t as u64) ^ (t >> 64) as u64
}

Expand Down

0 comments on commit 351a708

Please sign in to comment.