From c9e94c513a917ab997c5f766a00e68f98a5aa6fc Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 9 Jul 2012 20:03:33 +0000 Subject: RandomCmwc was far too static before, now it's seeded with the Basic generator. --- src/stable/randomcmwc.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'src') 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 @@ #include "bu/randomcmwc.h" +#include "bu/randombasic.h" + #define PHI 0x9e3779b9 Bu::RandomCmwc::RandomCmwc() : @@ -23,14 +25,24 @@ Bu::RandomCmwc::~RandomCmwc() void Bu::RandomCmwc::seed( int32_t iSeed ) { - i = 4096; + i = 4095; + c = 362436; + + Bu::RandomBasic rb; + rb.seed( iSeed ); + + for( int j = 0; j < 4096; j++ ) + q[j] = rb.rand(); + + c = rb.rand(); - q[0] = iSeed; - q[1] = iSeed + PHI; - q[2] = iSeed + PHI + PHI; + return; + q[0] = (uint32_t)rb.rand(); + q[1] = (uint32_t)rb.rand() + PHI; + q[2] = (uint32_t)rb.rand() + PHI + PHI; for (int j = 3; j < 4096; j++) - q[j] = q[j - 3] ^ q[j - 2] ^ PHI ^ j; + q[j] = q[j - 3] ^ q[j - 2] ^ PHI ^ j; } int32_t Bu::RandomCmwc::rand() -- cgit v1.2.3