aboutsummaryrefslogtreecommitdiff
path: root/src/stable/randomcmwc.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-07-09 20:03:33 +0000
committerMike Buland <eichlan@xagasoft.com>2012-07-09 20:03:33 +0000
commitc9e94c513a917ab997c5f766a00e68f98a5aa6fc (patch)
treed51a745550a46996ccbb5335dd19de11118a7872 /src/stable/randomcmwc.cpp
parent87fa2298eb73bf6213ec836937c236df25e2a4a7 (diff)
downloadlibbu++-c9e94c513a917ab997c5f766a00e68f98a5aa6fc.tar.gz
libbu++-c9e94c513a917ab997c5f766a00e68f98a5aa6fc.tar.bz2
libbu++-c9e94c513a917ab997c5f766a00e68f98a5aa6fc.tar.xz
libbu++-c9e94c513a917ab997c5f766a00e68f98a5aa6fc.zip
RandomCmwc was far too static before, now it's seeded with the Basic generator.
Diffstat (limited to 'src/stable/randomcmwc.cpp')
-rw-r--r--src/stable/randomcmwc.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/stable/randomcmwc.cpp b/src/stable/randomcmwc.cpp
index ccfc4a9..9f68982 100644
--- a/src/stable/randomcmwc.cpp
+++ b/src/stable/randomcmwc.cpp
@@ -7,6 +7,8 @@
7 7
8#include "bu/randomcmwc.h" 8#include "bu/randomcmwc.h"
9 9
10#include "bu/randombasic.h"
11
10#define PHI 0x9e3779b9 12#define PHI 0x9e3779b9
11 13
12Bu::RandomCmwc::RandomCmwc() : 14Bu::RandomCmwc::RandomCmwc() :
@@ -23,14 +25,24 @@ Bu::RandomCmwc::~RandomCmwc()
23 25
24void Bu::RandomCmwc::seed( int32_t iSeed ) 26void Bu::RandomCmwc::seed( int32_t iSeed )
25{ 27{
26 i = 4096; 28 i = 4095;
29 c = 362436;
30
31 Bu::RandomBasic rb;
32 rb.seed( iSeed );
33
34 for( int j = 0; j < 4096; j++ )
35 q[j] = rb.rand();
36
37 c = rb.rand();
27 38
28 q[0] = iSeed; 39 return;
29 q[1] = iSeed + PHI; 40 q[0] = (uint32_t)rb.rand();
30 q[2] = iSeed + PHI + PHI; 41 q[1] = (uint32_t)rb.rand() + PHI;
42 q[2] = (uint32_t)rb.rand() + PHI + PHI;
31 43
32 for (int j = 3; j < 4096; j++) 44 for (int j = 3; j < 4096; j++)
33 q[j] = q[j - 3] ^ q[j - 2] ^ PHI ^ j; 45 q[j] = q[j - 3] ^ q[j - 2] ^ PHI ^ j;
34} 46}
35 47
36int32_t Bu::RandomCmwc::rand() 48int32_t Bu::RandomCmwc::rand()