// Prog: random.C
// implement a class for pseudorandom numbers.
#include
namespace ifm {
// class random: implementation
random::random(unsigned int a, unsigned int c,
unsigned int m, 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