-
Notifications
You must be signed in to change notification settings - Fork 0
/
xorshf96.c
44 lines (33 loc) · 792 Bytes
/
xorshf96.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
static unsigned long xorshf96(void) { /* A George Marsaglia generator, period 2^96-1 */
static unsigned long x=123456789, y=362436069, z=521288629;
unsigned long t;
x ^= x << 16;
x ^= x >> 5;
x ^= x << 1;
t = x;
x = y;
y = z;
z = t ^ x ^ y;
return z;
}
inline unsigned long random(void) {
return xorshf96();
}
inline float ranf(void) {
return (float) random() / (float) (~0UL);
}
inline float ranfu(void) {
return (float) random()/((~0UL>>1)*1.0) - 1.0;
}
int main(void) {
unsigned i, quantity=100e6;
float f;
for (i=quantity/2; i; i--) {
xorshf96();
xorshf96();
}
for (i=0; i<20; i++) {
printf("%21.018lf\n", xorshf96()/((~0UL>>1)*1.0) - 1.0);
}
return 0;
}