Skip to content

Commit 351a708

Browse files
Bluefingernotgull
authored andcommitted
Use wyrand final v4.2 constants for gen_u64()
1 parent 63175fa commit 351a708

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/lib.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,14 @@ impl Rng {
148148
/// Generates a random `u64`.
149149
#[inline]
150150
fn gen_u64(&mut self) -> u64 {
151-
let s = self.0.wrapping_add(0xA0761D6478BD642F);
151+
// Constants for WyRand taken from: https://github.com/wangyi-fudan/wyhash/blob/master/wyhash.h#L151
152+
// Updated for the final v4.2 implementation with improved constants for better entropy output.
153+
const WY_CONST_0: u64 = 0x2d35_8dcc_aa6c_78a5;
154+
const WY_CONST_1: u64 = 0x8bb8_4b93_962e_acc9;
155+
156+
let s = self.0.wrapping_add(WY_CONST_0);
152157
self.0 = s;
153-
let t = u128::from(s) * u128::from(s ^ 0xE7037ED1A0B428DB);
158+
let t = u128::from(s) * u128::from(s ^ WY_CONST_1);
154159
(t as u64) ^ (t >> 64) as u64
155160
}
156161

0 commit comments

Comments
 (0)