00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef RANDOMNUMBERGENERATORS_HPP_
00031 #define RANDOMNUMBERGENERATORS_HPP_
00032
00033 #include <boost/serialization/access.hpp>
00034 #include <boost/serialization/split_member.hpp>
00035
00040 class RandomNumberGenerator
00041 {
00042 public:
00043
00044
00049 double StandardNormalRandomDeviate();
00050
00058 double NormalRandomDeviate(double mean, double sd);
00059
00063 double ranf();
00064
00071 unsigned randMod(unsigned base);
00072
00082 void Shuffle(unsigned num, std::vector<unsigned>& rValues);
00083
00088 static RandomNumberGenerator* Instance();
00089
00096 static void Destroy();
00097
00103 void Reseed(int seed);
00104
00105 protected:
00106
00111 RandomNumberGenerator();
00112
00113 private:
00114
00116 int mSeed;
00117
00119 unsigned mTimesCalled;
00120
00122 static RandomNumberGenerator *mpInstance;
00123
00124 friend class boost::serialization::access;
00136 template<class Archive>
00137 void save(Archive & archive, const unsigned int version) const
00138 {
00139
00140 archive & mSeed;
00141 archive & mTimesCalled;
00142 }
00154 template<class Archive>
00155 void load(Archive & archive, const unsigned int version)
00156 {
00157 archive & mSeed;
00158 archive & mTimesCalled;
00159
00160 srandom(mSeed);
00161
00162
00163
00164
00165
00166 for (unsigned i=0; i<mTimesCalled; i++)
00167 {
00168 random();
00169 }
00170 }
00171 BOOST_SERIALIZATION_SPLIT_MEMBER()
00172
00173 };
00174 #endif