double darts(long n) { long k = 0; int i = 0; double x = 0, y = 0; uniform_init(); for(i = 0;i < n;i++) { x = uniform_double(0, 1); /*y = uniform_double(0, 1);*/ y = x; /*printf("%f %f\n", x, y);*/ if(x*x + y*y <= 1) k++; } uniform_close(); /*printf("%ld\n", k);*/ return 4.0*k/n; }
/** * Sets the range of the subsequent calls to nextValue() * @param start :: The lowest value a call to nextValue() will produce * @param end :: The largest value a call to nextValue() will produce */ void MersenneTwister::setRange(const double start, const double end) { m_uniform_dist = uniform_double(start,end); }
/// Returns a flat random number between 0.0 & 1.0 double RandomNumberGenerator::flat() { typedef boost::variate_generator<boost::mt19937 &, uniform_double> uniform_generator; return uniform_generator(m_generator, uniform_double(0.0, 1.0))(); }