#include #include #include static const double Sqr2Pi = 2.50662827463100050240; /* sqrt(2*pi) */ /* I do *not* recommend using the following pseudo random number generator for * important applications. Use one from a proper scientific library. */ #include #define u01rand() ((double)rand()/RAND_MAX) double crude_randn() { int i; double sum = 0; for (i=0; i<12; i++) { sum += u01rand(); } return (sum - 6.0); } int main() { #define NUM_BINS 50 const int num_trials = 1e6; const double min_x = -6.0; const double max_x = +6.0; int counts[NUM_BINS]; double bin_width = (max_x - min_x) / NUM_BINS; FILE* fid; int i; int bin; double bin_mid; double rn; double clt_est; for (i=0; i= 0); assert(bin < NUM_BINS); counts[bin] += 1; } /* Output to space-separated text file with columns: * bin-center count expected-count */ fid = fopen("hist.txt", "w"); assert(fid); for (i=0; i