#include // for time() #include // for INT_MAX #include // for rand/srand #include "rando.h" int RandGen::initialized = 0; RandGen::RandGen() // postcondition: system srandom used to initialize seed // once per program { if (0 == initialized){ initialized = 1; // only call srand once srand(time(0)); // randomize } } int RandGen::RandInt(int max) // precondition: max > 0 // postcondition: returns int in [0..max) { return rand() % max; } int RandGen::RandInt(int low, int max) // precondition: low <= max // postcondition: returns int in [low..max] { return low + RandInt(max-low+1); } double RandGen::RandReal() // postcondition: returns double in [0..1) { return RandInt() / double(INT_MAX); }