--- libutil/random.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/libutil/random.c b/libutil/random.c index 72385fb..15082e5 100644 --- a/libutil/random.c +++ b/libutil/random.c _AT_@ -21,7 +21,7 @@ rng32(void) } void -rng32_randomseed() +rng32_seed() { return; } _AT_@ -41,8 +41,8 @@ rng32(void) uint64_t oldstate = globalstate; uint32_t r, v; - *state *= 6364136223846793005ULL; - *state += globalid; /* we must have it as odd */ + globalstate *= 6364136223846793005ULL; + globalstate += 1442695040888963407ULL; /* we must have it as odd */ r = oldstate >> (64 - 5); v = (oldstate ^ (oldstate >> 18)) >> (32 - 5); _AT_@ -51,12 +51,11 @@ rng32(void) } void -rng32_randomseed(void) +rng32_seed(void) { struct timespec ts; clock_gettime(CLOCK_REALTIME, &ts); globalstate = (intptr_t)&printf ^ ts.tv_sec ^ ((unsigned long)ts.tv_nsec * 0xAC5533CD); - globalid = 1442695040888963407ULL; } #endif /* standalone, PCG construction */ _AT_@ -70,15 +69,15 @@ rng32_bounded(uint32_t bound) { uint32_t x = rng32(); uint64_t m = (uint64_t)x * (uint64_t)bound; uint32_t l = (uint32_t)m; - if (l < range) { - uint32_t t = -range; - if (t >= range) { - t -= range; - if (t >= range) - t %= range; + if (l < bound) { + uint32_t t = -bound; + if (t >= bound) { + t -= bound; + if (t >= bound) + t %= bound; } while (l < t) { - x = rng32(state, id); + x = rng32(); m = (uint64_t)x * (uint64_t)bound; l = (uint32_t)m; } -- 2.47.1Received on Fri Dec 20 2024 - 16:06:00 CET
This archive was generated by hypermail 2.3.0 : Fri Dec 20 2024 - 16:12:45 CET