/*************************************************************************** * Copyright (C) 1995, 1996, 1997 Jun Sun, jsun@junsun.net. * * * * This package contains a collection of distributions. For each dist- * * tribution there are desity function (mass function in discrete cases * * distribution function and random sample generator. * * * *************************************************************************** */ #include "LCG.h" #include static const unsigned long a = 314159269UL; static const unsigned long c = 453806245UL; static const unsigned long m = 2147483648UL; LCG::LCG() { seed=time(0);} // determine the seed by the current time LCG::LCG(long unsigned n) { seed = n; } void LCG::set_seed(long unsigned n) {seed = n; } double LCG::sample() { seed = (seed*a + c) % m; if (seed==0) seed = c; return (double)seed / (double)m; }