-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWELLRNG512Gen.h
33 lines (32 loc) · 990 Bytes
/
WELLRNG512Gen.h
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
class WELLRNG512Generator {
unsigned long state[16];
int index = 0;
public:
WELLRNG512Generator() {
std::random_device rd;
std::mt19937 rand(rd());
for (int i = 0; i < 16; i++)
state[i] = rand();
}
WELLRNG512Generator(const int &seed) {
std::mt19937 rand(seed);
for (int i = 0; i < 16; i++)
state[i] = rand();
}
unsigned long Generate() {
// http://www.gamedevforever.com/114
unsigned long a, b, c, d;
a = state[index];
c = state[(index+13)&15];
b = a^c^(a<<16)^(c<<15);
c = state[(index+9)&15];
c ^= (c>>11);
a = state[index] = b^c;
d = a^((a<<5)&0xDA442D20UL);
index = (index + 15)&15;
a = state[index];
state[index] = a^b^d^(a<<2)^(b<<18)^(c<<28);
return state[index];
}
};