From 16755caa33ee7229182679e1675cc81f73164b28 Mon Sep 17 00:00:00 2001 From: Christopher Swenson Date: Mon, 12 Feb 2024 17:18:56 -0800 Subject: [PATCH] is rand_s broken --- stresstest.c | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/stresstest.c b/stresstest.c index 8581b87..cc139ac 100644 --- a/stresstest.c +++ b/stresstest.c @@ -62,21 +62,47 @@ static __inline int simple_cmp(const void *a, const void *b) { #ifdef _WIN32 #include +/* Written in 2015 by Sebastiano Vigna (vigna@acm.org) + +To the extent possible under law, the author has dedicated all copyright +and related and neighboring rights to this software to the public domain +worldwide. This software is distributed without any warranty. + +See . */ + +#include + +/* This is a fixed-increment version of Java 8's SplittableRandom generator + See http://dx.doi.org/10.1145/2714064.2660195 and + http://docs.oracle.com/javase/8/docs/api/java/util/SplittableRandom.html + + It is a very fast generator passing BigCrush, and it can be useful if + for some reason you absolutely want 64 bits of state. */ + +static uint64_t x; /* The state can be seeded with any value. */ + +uint64_t next() { + uint64_t z = (x += 0x9e3779b97f4a7c15); + z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9; + z = (z ^ (z >> 27)) * 0x94d049bb133111eb; + return z ^ (z >> 31); +} static __inline void srand48(long seed) { - srand(seed); + //srand(seed); + x = seed; } static __inline long lrand48(void) { - int x; - rand_s(&x); - return x & 0x7fffffff; + return next() & 0x7fffffff; + // int x; + // rand_s(&x); + // return x & 0x7fffffff; } static __inline double utime(void) { - //struct timespec ts; - //timespec_get(&ts, TIME_UTC); - //return 1000000.0 * ts.tv_sec + ts.tv_nsec / 1000.0; - return lrand48(); + struct timespec ts; + timespec_get(&ts, TIME_UTC); + return 1000000.0 * ts.tv_sec + ts.tv_nsec / 1000.0; } #else