Skip to content

Commit 16755ca

Browse files
committed
is rand_s broken
1 parent 7b9b209 commit 16755ca

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

stresstest.c

+34-8
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,47 @@ static __inline int simple_cmp(const void *a, const void *b) {
6262
#ifdef _WIN32
6363

6464
#include <time.h>
65+
/* Written in 2015 by Sebastiano Vigna ([email protected])
66+
67+
To the extent possible under law, the author has dedicated all copyright
68+
and related and neighboring rights to this software to the public domain
69+
worldwide. This software is distributed without any warranty.
70+
71+
See <http://creativecommons.org/publicdomain/zero/1.0/>. */
72+
73+
#include <stdint.h>
74+
75+
/* This is a fixed-increment version of Java 8's SplittableRandom generator
76+
See http://dx.doi.org/10.1145/2714064.2660195 and
77+
http://docs.oracle.com/javase/8/docs/api/java/util/SplittableRandom.html
78+
79+
It is a very fast generator passing BigCrush, and it can be useful if
80+
for some reason you absolutely want 64 bits of state. */
81+
82+
static uint64_t x; /* The state can be seeded with any value. */
83+
84+
uint64_t next() {
85+
uint64_t z = (x += 0x9e3779b97f4a7c15);
86+
z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9;
87+
z = (z ^ (z >> 27)) * 0x94d049bb133111eb;
88+
return z ^ (z >> 31);
89+
}
6590
static __inline void srand48(long seed) {
66-
srand(seed);
91+
//srand(seed);
92+
x = seed;
6793
}
6894

6995
static __inline long lrand48(void) {
70-
int x;
71-
rand_s(&x);
72-
return x & 0x7fffffff;
96+
return next() & 0x7fffffff;
97+
// int x;
98+
// rand_s(&x);
99+
// return x & 0x7fffffff;
73100
}
74101

75102
static __inline double utime(void) {
76-
//struct timespec ts;
77-
//timespec_get(&ts, TIME_UTC);
78-
//return 1000000.0 * ts.tv_sec + ts.tv_nsec / 1000.0;
79-
return lrand48();
103+
struct timespec ts;
104+
timespec_get(&ts, TIME_UTC);
105+
return 1000000.0 * ts.tv_sec + ts.tv_nsec / 1000.0;
80106
}
81107
#else
82108

0 commit comments

Comments
 (0)