00001
00006 #ifndef GENETIK_UTIL_RANDOM
00007 #define GENETIK_UTIL_RANDOM
00008
00009 #include "Log.h"
00010
00011 namespace genetiK
00012 {
00013 namespace util
00014 {
00015
00023 class Random
00024 {
00025 protected:
00026
00032 Random();
00033
00034 virtual ~Random();
00035 private:
00036 static Random* implementation;
00037
00038 public:
00044 static void setImplementation(Random* random);
00045
00052 static void setDefaultImplementation();
00053
00059 inline static Random* getImplementation()
00060 {
00061 if (!implementation)
00062 Log::getInstance()->warn("Warning: You should call setImplementation before calling Random::getImplentation().");
00063 return implementation;
00064 }
00069 static void deleteImplementation();
00070
00076 virtual unsigned int getNextInt()=0;
00077
00085 virtual unsigned int getNextInt(unsigned int max)=0;
00086
00092 virtual double getNextReal()=0;
00093
00094 };
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00126 class RandomDefault : public Random{
00127 private:
00128
00129 #if 0
00130
00131
00132 static const unsigned int MERS_N 351
00133 static const unsigned int MERS_M 175
00134 static const unsigned int MERS_R 19
00135 static const unsigned int MERS_U 11
00136 static const unsigned int MERS_S 7
00137 static const unsigned int MERS_T 15
00138 static const unsigned int MERS_L 17
00139 static const unsigned int MERS_A 0xE4BD75F5
00140 static const unsigned int MERS_B 0x655E5280
00141 static const unsigned int MERS_C 0xFFD58000
00142 #else
00143
00144 static const unsigned int MERS_N = 624;
00145 static const unsigned int MERS_M = 397;
00146 static const unsigned int MERS_R = 31;
00147 static const unsigned int MERS_U = 11;
00148 static const unsigned int MERS_S = 7;
00149 static const unsigned int MERS_T = 15;
00150 static const unsigned int MERS_L = 18;
00151 static const unsigned int MERS_A = 0x9908B0DF;
00152 static const unsigned int MERS_B = 0x9D2C5680;
00153 static const unsigned int MERS_C = 0xEFC60000;
00154 #endif
00155
00156 unsigned int stateVector[MERS_N];
00157 unsigned short int stateVectorIndex;
00158
00159 unsigned long int seed;
00160 public:
00164 RandomDefault(unsigned int seed);
00165 virtual ~RandomDefault();
00171 virtual unsigned int getNextInt();
00172
00180 virtual unsigned int getNextInt(unsigned int max);
00181
00187 virtual double getNextReal();
00188 };
00189
00190 }
00191 }
00192
00193 #endif