-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathjkiss.cpp
54 lines (47 loc) · 954 Bytes
/
jkiss.cpp
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
44
45
46
47
48
49
50
51
52
53
54
#include "jkiss.h"
// David Jone's JKISS generator, ported from the C source written by the same.
JKISS::JKISS() {
_x = 123456789;
_y = 987654321;
_z = 43219876;
_c = 6543217;
}
RNG*
JKISS::split()
{
RNG* k = new JKISS();
k->seed(this);
return k;
}
void
JKISS::seed(uint32_t s)
{
_y = s;
}
void
JKISS::seed(RNG *rng)
{
_x = rng->get_uint32();
_y = rng->get_nonzero_bits(32);
_z = rng->get_uint32();
if(!_z) {
_c = rng->get_nonzero_bits(32);
} else {
_c = rng->get_uint32();
}
}
uint32_t
JKISS::get_uint32()
{
uint64_t t;
uint32_t y = _y;
_x = 314527869 * _x + 1234567;
y ^= y << 5;
y ^= y >> 7;
y ^= y << 22;
_y = y;
t = 4294584393ULL * _z + _c;
_c = t >> 32;
_z = t;
return (_x + y + _z);
}