From 0584a78d9b59bc84e166c735af466fed740b00f9 Mon Sep 17 00:00:00 2001 From: wiire-a Date: Thu, 11 Jan 2018 15:23:16 +0100 Subject: [PATCH] Fixed issue with previous changes in glibc PRNG With the previous changes the PRNG was faster but didn't work on all instances. --- src/random/glibc_random_yura.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/random/glibc_random_yura.c b/src/random/glibc_random_yura.c index c5076f4..64c69c5 100644 --- a/src/random/glibc_random_yura.c +++ b/src/random/glibc_random_yura.c @@ -26,7 +26,9 @@ static inline uint32_t *glibc_fast_nonce(uint32_t seed, uint32_t *dest) /* This does: seed = (16807LL * seed) % 0x7fffffff using the sum of digits method which works for mod N, base N+1 */ - const uint64_t p = 16807ULL * seed; /* Seed is always positive (31 bits) */ + /* Doesn't work for seed = 0x7fffffff or 0xfffffffe */ + uint64_t p = 16807ULL * seed; + p = (p >> 31) + (p & 0x7fffffff); seed = (p >> 31) + (p & 0x7fffffff); } dest[0] = word0 >> 1; @@ -45,7 +47,9 @@ static inline uint32_t glibc_fast_seed(uint32_t seed) /* This does: seed = (16807LL * seed) % 0x7fffffff using the sum of digits method which works for mod N, base N+1 */ - const uint64_t p = 16807ULL * seed; /* Seed is always positive (31 bits) */ + /* Doesn't work for seed = 0x7fffffff or 0xfffffffe */ + uint64_t p = 16807ULL * seed; + p = (p >> 31) + (p & 0x7fffffff); seed = (p >> 31) + (p & 0x7fffffff); } return (word0 + seed * glibc_seed_tbl[33]) >> 1;