/* Central Limit Theorem Demonstration: For lab
*/
#include
#include
/* generates flat random numbers between 0.0 and 1.0 */
/* BUT, put a hole in that it gives no randoms between .35 and .45
and has a dip from .73 to .83
And has option of averaging a number of the random numbers before printing.
*/
int main (int argc, char *argv[])
{
const gsl_rng_type * T;
gsl_rng * r;
double u, uprev, avgout;
int i, n, j, flag, avgn, nout, seed;
gsl_rng_env_setup();
T = gsl_rng_default;
r = gsl_rng_alloc (T);
nout = atoi(argv[1]); // total number of numbers you want
avgn = atoi(argv[2]); // how many to average at a time
seed = atoi(argv[3]); // random seed....how many numbers to skip before starting.
// go through seeds
for (i = 0; i .25)){
n=n+1;
flag = 0; //don't pass any in this range.
}
if ( ((u<.83)&&(u>.73))&&(uprev <.25)) {
n=n+1;
flag =0; // don't pass
}
uprev = u;
// u = u-.5; // center for simplicity, before averaging/displaying
avgout = avgout + u*(double)(flag);
// print them out...for testing purposes.
// printf("%.5f\n", u);
}
avgout = avgout/(double)(avgn);
printf("%.7f\n", avgout);
}
gsl_rng_free (r);
return 0;
}