#include #include #include #include #include "mersenne.h" using namespace std; #define ARRAYELEMCOUNT(x) sizeof(x) / sizeof(x[0]) #define TAB "\t" typedef unsigned int uint; class CRandu //========== { public: CRandu() : m_Rnd(time(0)) {} inline void Seed(uint seed) {m_Rnd = seed;} inline uint RandInt31Bit() //------------------------ { m_Rnd = (65539 * m_Rnd) % 2147483648; //2147483648 == 2^31 return m_Rnd; } //Return 'random' number from ]0,1] inline double Rand() //-------------------- { return RandInt31Bit() / 2147483647.0; } private: uint m_Rnd; }; int main() //-------- { bool runPartA = true; bool runPartB = true; if(runPartA) { const uint seeds[] = {1, 4, 32, 58804, 32768, 65536, 574042, 5444066, 268435456, 1846665012}; cout << "#Seed\tCycle length " << endl; for(uint i = 0; i=2^31, this conditions is always true -> infinite loop. //So here simply expecting seed to be < 2^31. cout.width(12); cout << seeds[i] << TAB << counter << endl; } } if(runPartB) { cout << "Starting part b" << endl; ofstream randudatastrm("randudata.txt", ios::trunc); const uint seeds[] = {1, 4, 32}; const uint hitlimit = 1000; for(uint i = 0; i