#include "random.h" #include #include using namespace std; //======================================================== // setseed //======================================================== void Random::setseed(int seed) { srandom((unsigned) seed); }; //======================================================== // uniformRandom() //======================================================== double Random::uniformRandom() { double x = ((double)(labs(random())))/0x10000000; return x - floor(x); } //======================================================== // uniformRandom(double) //======================================================== double Random::uniformRandom(double mean) { return uniformRandom()*(2*mean); } //======================================================== // exponentialRandom //======================================================== double Random::exponentialRandom(double mean) { return -mean * log(1 - uniformRandom()); }