diff options
Diffstat (limited to 'src/stable/randomcmwc.cpp')
-rw-r--r-- | src/stable/randomcmwc.cpp | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/src/stable/randomcmwc.cpp b/src/stable/randomcmwc.cpp index 9f68982..1d4a913 100644 --- a/src/stable/randomcmwc.cpp +++ b/src/stable/randomcmwc.cpp | |||
@@ -12,52 +12,52 @@ | |||
12 | #define PHI 0x9e3779b9 | 12 | #define PHI 0x9e3779b9 |
13 | 13 | ||
14 | Bu::RandomCmwc::RandomCmwc() : | 14 | Bu::RandomCmwc::RandomCmwc() : |
15 | q( 0 ), | 15 | q( 0 ), |
16 | c( 362436 ) | 16 | c( 362436 ) |
17 | { | 17 | { |
18 | q = new uint32_t[4096]; | 18 | q = new uint32_t[4096]; |
19 | } | 19 | } |
20 | 20 | ||
21 | Bu::RandomCmwc::~RandomCmwc() | 21 | Bu::RandomCmwc::~RandomCmwc() |
22 | { | 22 | { |
23 | delete[] q; | 23 | delete[] q; |
24 | } | 24 | } |
25 | 25 | ||
26 | void Bu::RandomCmwc::seed( int32_t iSeed ) | 26 | void Bu::RandomCmwc::seed( int32_t iSeed ) |
27 | { | 27 | { |
28 | i = 4095; | 28 | i = 4095; |
29 | c = 362436; | 29 | c = 362436; |
30 | 30 | ||
31 | Bu::RandomBasic rb; | 31 | Bu::RandomBasic rb; |
32 | rb.seed( iSeed ); | 32 | rb.seed( iSeed ); |
33 | 33 | ||
34 | for( int j = 0; j < 4096; j++ ) | 34 | for( int j = 0; j < 4096; j++ ) |
35 | q[j] = rb.rand(); | 35 | q[j] = rb.rand(); |
36 | 36 | ||
37 | c = rb.rand(); | 37 | c = rb.rand(); |
38 | 38 | ||
39 | return; | 39 | return; |
40 | q[0] = (uint32_t)rb.rand(); | 40 | q[0] = (uint32_t)rb.rand(); |
41 | q[1] = (uint32_t)rb.rand() + PHI; | 41 | q[1] = (uint32_t)rb.rand() + PHI; |
42 | q[2] = (uint32_t)rb.rand() + PHI + PHI; | 42 | q[2] = (uint32_t)rb.rand() + PHI + PHI; |
43 | 43 | ||
44 | for (int j = 3; j < 4096; j++) | 44 | for (int j = 3; j < 4096; j++) |
45 | q[j] = q[j - 3] ^ q[j - 2] ^ PHI ^ j; | 45 | q[j] = q[j - 3] ^ q[j - 2] ^ PHI ^ j; |
46 | } | 46 | } |
47 | 47 | ||
48 | int32_t Bu::RandomCmwc::rand() | 48 | int32_t Bu::RandomCmwc::rand() |
49 | { | 49 | { |
50 | uint64_t t, a = 18782LL; | 50 | uint64_t t, a = 18782LL; |
51 | uint32_t x, r = 0xfffffffe; | 51 | uint32_t x, r = 0xfffffffe; |
52 | i = (i + 1) & 4095; | 52 | i = (i + 1) & 4095; |
53 | t = a * q[i] + c; | 53 | t = a * q[i] + c; |
54 | c = (t >> 32); | 54 | c = (t >> 32); |
55 | x = t + c; | 55 | x = t + c; |
56 | if( x < c ) | 56 | if( x < c ) |
57 | { | 57 | { |
58 | x++; | 58 | x++; |
59 | c++; | 59 | c++; |
60 | } | 60 | } |
61 | return (q[i] = r - x); | 61 | return (q[i] = r - x); |
62 | } | 62 | } |
63 | 63 | ||