Minor tweaks to Owen scrambling functions.
This commit is contained in:
parent
ef489c1ca2
commit
98a9aeb374
|
@ -6,12 +6,11 @@ pub fn owen2(n: u32, seed: u32) -> u32 {
|
|||
// This is to ensure that the seed doesn't behave poorly with
|
||||
// e.g. incrementing parameters, and also that zero doesn't
|
||||
// map to zero in the hash function.
|
||||
let seed = seed.wrapping_mul(0xe8559dcb) ^ 0x372fcdb9;
|
||||
let seed = seed.wrapping_mul(0x68318d2f) ^ 0x5adbc2a7;
|
||||
|
||||
let mut result = n;
|
||||
for i in 0..32 {
|
||||
let mask = (!0 << 1) << i; // Two shifts to avoid undefined overflow.
|
||||
result ^= hash((n & mask) ^ seed) & (1 << i);
|
||||
result ^= hash((n & (!1 << i)) ^ seed) & (1 << i);
|
||||
}
|
||||
|
||||
result
|
||||
|
@ -55,7 +54,7 @@ pub fn owen4(n: u32, seed: u32) -> u32 {
|
|||
|
||||
let mut result = 0;
|
||||
for i in 0..16 {
|
||||
let mask = (!0 << 2) << (i * 2); // Two shifts to avoid undefined overflow.
|
||||
let mask = !0b11 << (i * 2);
|
||||
let perm_entry = PERMUTATION_TABLE[
|
||||
// The xor with `i` is to ensure runs of zeros in `n` still
|
||||
// result in different shuffles on each iteration. `i` is
|
||||
|
|
Loading…
Reference in New Issue
Block a user