diff options
| author | Mike Buland <eichlan@xagasoft.com> | 2012-11-09 18:15:04 +0000 |
|---|---|---|
| committer | Mike Buland <eichlan@xagasoft.com> | 2012-11-09 18:15:04 +0000 |
| commit | 79843b51267d7a8faf8e9dcee09fa5e167373e6d (patch) | |
| tree | cc317f202fa6b7b68908af9bee1848355681db78 /src/stable | |
| parent | ba177923d7b60800ae2e01f80fc10dc8ad1594bb (diff) | |
| download | libbu++-79843b51267d7a8faf8e9dcee09fa5e167373e6d.tar.gz libbu++-79843b51267d7a8faf8e9dcee09fa5e167373e6d.tar.bz2 libbu++-79843b51267d7a8faf8e9dcee09fa5e167373e6d.tar.xz libbu++-79843b51267d7a8faf8e9dcee09fa5e167373e6d.zip | |
Added seed parameter to constructor of two PRNGs. Also fixed horrible mistake
in RandomBasic.
Diffstat (limited to 'src/stable')
| -rw-r--r-- | src/stable/randombasic.cpp | 11 | ||||
| -rw-r--r-- | src/stable/randombasic.h | 16 | ||||
| -rw-r--r-- | src/stable/randomcmwc.cpp | 3 | ||||
| -rw-r--r-- | src/stable/randomcmwc.h | 2 |
4 files changed, 23 insertions, 9 deletions
diff --git a/src/stable/randombasic.cpp b/src/stable/randombasic.cpp index e253b70..fe8843b 100644 --- a/src/stable/randombasic.cpp +++ b/src/stable/randombasic.cpp | |||
| @@ -7,10 +7,11 @@ | |||
| 7 | 7 | ||
| 8 | #include "bu/randombasic.h" | 8 | #include "bu/randombasic.h" |
| 9 | 9 | ||
| 10 | Bu::RandomBasic::RandomBasic() : | 10 | #define a (6364136223846793005ll) |
| 11 | a( 6364136223846793005ll ), | 11 | #define c (1442695040888963407ll) |
| 12 | c( 1442695040888963407ll ), | 12 | |
| 13 | x( 0 ) | 13 | Bu::RandomBasic::RandomBasic( int32_t iSeed ) : |
| 14 | x( iSeed ) | ||
| 14 | { | 15 | { |
| 15 | } | 16 | } |
| 16 | 17 | ||
| @@ -20,7 +21,7 @@ Bu::RandomBasic::~RandomBasic() | |||
| 20 | 21 | ||
| 21 | void Bu::RandomBasic::seed( int32_t iSeed ) | 22 | void Bu::RandomBasic::seed( int32_t iSeed ) |
| 22 | { | 23 | { |
| 23 | c = iSeed; | 24 | x = iSeed; |
| 24 | } | 25 | } |
| 25 | 26 | ||
| 26 | int32_t Bu::RandomBasic::rand() | 27 | int32_t Bu::RandomBasic::rand() |
diff --git a/src/stable/randombasic.h b/src/stable/randombasic.h index 4d1c2f8..c9b7072 100644 --- a/src/stable/randombasic.h +++ b/src/stable/randombasic.h | |||
| @@ -11,10 +11,22 @@ | |||
| 11 | 11 | ||
| 12 | namespace Bu | 12 | namespace Bu |
| 13 | { | 13 | { |
| 14 | /** | ||
| 15 | * Basic Linear Congruential Generator. This is one of the simplest and | ||
| 16 | * most common pseudo-random number generators out there. It's simple, | ||
| 17 | * fast, and does a decent job if you don't have any stastistical | ||
| 18 | * requirements other than "random looking." This is the algorithm included | ||
| 19 | * as the default random number generator in most standard libraries, | ||
| 20 | * although this one uses larger numbers internally, has a longer period, | ||
| 21 | * and more even distrubition of randomness accross it's bits than most | ||
| 22 | * implementations. | ||
| 23 | * | ||
| 24 | * The base values were published by Donald Knuth. | ||
| 25 | */ | ||
| 14 | class RandomBasic : public RandomBase | 26 | class RandomBasic : public RandomBase |
| 15 | { | 27 | { |
| 16 | public: | 28 | public: |
| 17 | RandomBasic(); | 29 | RandomBasic( int32_t iSeed=0 ); |
| 18 | virtual ~RandomBasic(); | 30 | virtual ~RandomBasic(); |
| 19 | 31 | ||
| 20 | virtual void seed( int32_t iSeed ); | 32 | virtual void seed( int32_t iSeed ); |
| @@ -22,7 +34,7 @@ namespace Bu | |||
| 22 | virtual int32_t rand(); | 34 | virtual int32_t rand(); |
| 23 | 35 | ||
| 24 | private: | 36 | private: |
| 25 | int64_t a, c, x; | 37 | int64_t x; |
| 26 | }; | 38 | }; |
| 27 | }; | 39 | }; |
| 28 | 40 | ||
diff --git a/src/stable/randomcmwc.cpp b/src/stable/randomcmwc.cpp index 1d4a913..b1c3cdb 100644 --- a/src/stable/randomcmwc.cpp +++ b/src/stable/randomcmwc.cpp | |||
| @@ -11,11 +11,12 @@ | |||
| 11 | 11 | ||
| 12 | #define PHI 0x9e3779b9 | 12 | #define PHI 0x9e3779b9 |
| 13 | 13 | ||
| 14 | Bu::RandomCmwc::RandomCmwc() : | 14 | Bu::RandomCmwc::RandomCmwc( int32_t iSeed ) : |
| 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 | seed( iSeed ); | ||
| 19 | } | 20 | } |
| 20 | 21 | ||
| 21 | Bu::RandomCmwc::~RandomCmwc() | 22 | Bu::RandomCmwc::~RandomCmwc() |
diff --git a/src/stable/randomcmwc.h b/src/stable/randomcmwc.h index 547b5bb..50eb8c4 100644 --- a/src/stable/randomcmwc.h +++ b/src/stable/randomcmwc.h | |||
| @@ -14,7 +14,7 @@ namespace Bu | |||
| 14 | class RandomCmwc : public RandomBase | 14 | class RandomCmwc : public RandomBase |
| 15 | { | 15 | { |
| 16 | public: | 16 | public: |
| 17 | RandomCmwc(); | 17 | RandomCmwc( int32_t iSeed=0 ); |
| 18 | virtual ~RandomCmwc(); | 18 | virtual ~RandomCmwc(); |
| 19 | 19 | ||
| 20 | virtual void seed( int32_t iSeed ); | 20 | virtual void seed( int32_t iSeed ); |
