Department of Computer Science | Institute of Theoretical Computer Science | CADMO

Theory of Combinatorial Algorithms

Prof. Emo Welzl and Prof. Bernd Gärtner

// Prog: random.cpp // implement a class for pseudorandom numbers. #include namespace ifm { // class random: implementation random::random(const unsigned int a, const unsigned int c, const unsigned int m, const unsigned int x0) : a_(a), c_(c), m_(m), xi_(x0) {} double random::operator()() { // update xi acording to formula,... xi_ = (a_ * xi_ + c_) % m_; // ...normalize it to [0,1), and return it return double(xi_) / m_; } } // end namespace ifm