How Does This Work? class RandomT Why this seed is not int seed; declared as static? static const int m 0x7fffffffL; static const int a 16807L; What happens if we /∥private function define is as static? int nextO; public: How do we initialize the seed? constructor functions //random generator for different purpose How do we protect the int nextInteger(int lower,int upper); seed and the random double nextDouble(double lower,double upper); number generate bool nextBoolean (double p); algorithm? };
How Does This Work? How Does This Work? class RandomT { int seed; static const int m = 0x7fffffffL; static const int a = 16807L; // private function int next(); public: // constructor functions //random generator for different purpose int nextInteger (int lower, int upper); double nextDouble (double lower, double upper); bool nextBoolean (double p); }; • Why this seed is not declared as static? • What happens if we define is as static? • How do we initialize the seed? • How do we protect the seed and the random number generate algorithm?
上海交通大学 main O 联合 RollDie 1811 UM-SJTU Jo University of Michigan dieFaceNum seed Call Stack intFace1 intFace2 void RollDie (void) 0 { 0 RandomT dieFaceNum; faceNum int intFacel=0,intFace2 =0,... 0 for (int i=0;i<=RAND MAX;i++) { int faceNum=dieFaceNum.nextInteger (1,6); if (faceNum==1) intFacel++; } else if (faceNum =2) { intFace2++;
Call Stack Call Stack void RollDie (void) { RandomT dieFaceNum; int intFace1 = 0, intFace2 = 0, ... for (int i = 0; i <= RAND_MAX; i++) { int faceNum = dieFaceNum.nextInteger (1, 6); if (faceNum == 1) { intFace1++; } else if (faceNum == 2) { intFace2++;