diff options
Diffstat (limited to 'src/FastRandom.h')
-rw-r--r-- | src/FastRandom.h | 47 |
1 files changed, 35 insertions, 12 deletions
diff --git a/src/FastRandom.h b/src/FastRandom.h index cebebad96..64a087c97 100644 --- a/src/FastRandom.h +++ b/src/FastRandom.h @@ -22,6 +22,7 @@ salts, the values they get will be different. #pragma once +#include <random> @@ -30,18 +31,19 @@ salts, the values they get will be different. class cFastRandom { public: + cFastRandom(void); - /// Returns a random int in the range [0 .. a_Range - 1]; a_Range must be less than 1M + /** Returns a random int in the range [0 .. a_Range - 1]; a_Range must be less than 1M */ int NextInt(int a_Range); - /// Returns a random int in the range [0 .. a_Range - 1]; a_Range must be less than 1M; a_Salt is additional source of randomness + /** Returns a random int in the range [0 .. a_Range - 1]; a_Range must be less than 1M; a_Salt is additional source of randomness */ int NextInt(int a_Range, int a_Salt); - /// Returns a random float in the range [0 .. a_Range]; a_Range must be less than 1M + /** Returns a random float in the range [0 .. a_Range]; a_Range must be less than 1M */ float NextFloat(float a_Range); - /// Returns a random float in the range [0 .. a_Range]; a_Range must be less than 1M; a_Salt is additional source of randomness + /** Returns a random float in the range [0 .. a_Range]; a_Range must be less than 1M; a_Salt is additional source of randomness */ float NextFloat(float a_Range, int a_Salt); /** Returns a random float between 0 and 1. */ @@ -49,14 +51,35 @@ public: /** Returns a random int in the range [a_Begin .. a_End] */ int GenerateRandomInteger(int a_Begin, int a_End); - -protected: - int m_Seed; - int m_Counter; - - /// Counter that is used to initialize the seed, incremented for each object created - static int m_SeedCounter; -} ; + +private: + + std::minstd_rand m_LinearRand; +}; + + + + + +class MTRand +{ +public: + + MTRand(void); + + /** Returns a random integer in the range [0 .. a_Range]. */ + int randInt(int a_Range); + + /** Returns a random integer in the range [0 .. MAX_INT]. */ + int randInt(void); + + /** Returns a random floating point number in the range [0 .. a_Range]. */ + double rand(double a_Range); + +private: + + std::mt19937 m_MersenneRand; +}; |