#ifndef CA_UWATERLOO_ALUMNI_DWHARDER_CENTRAL_LIMIT_THEOREM #define CA_UWATERLOO_ALUMNI_DWHARDER_CENTRAL_LIMIT_THEOREM #include #include // Author: Douglas Wilhelm Harder // Copyright (c) 2011 by Douglas Wilhelm Harder. All rights reserved. // On successive calls to Normal_distributions::Central_limit_theorem::randn(), this function returns // a random standard normal value (a mean of zero and standard deviation of one). // // It generates twelve uniformly distributed values on the interval [0, 1], adds them, and subtracts // six giving a reasonably close approximation to a standard normal. namespace Normal_distributions { class Central_limit_theorem { public: static double randn(); }; double Central_limit_theorem::randn() { double u = 0.0; for ( int i = 0; i < 12; ++i ) { u += drand48(); } return u - 6.0; } } #endif