/*--------------------------------------------------------------*/ /* Program xdrand48 (Chapter 11) */ /* */ /* This program is written to test the drand48 () */ /* random number generator (See Chapter 11:Monte Carlo). */ /* */ #include #include main() { FILE *out; int i; double random, random_new; unsigned int seed=1; srand48(seed); out=fopen("output_drand.dat","w"); random=drand48(); for (i=1; i<=5000000000; i++) { random_new=drand48(); if ((random <= 0.000035) && (random_new <= 0.000035)) { fprintf(out, "%e %e \n", random, random_new); } random=random_new; } fclose(out); /* */ /* Now view the plot in output_drand.dat using Matlab. */ /* */ return EXIT_SUCCESS; } /*---------------------------------------------------------------*/