- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- int main()
- {
- FILE *file;
- int i;
- double n,m,w,x,y,z;
- n=0.5;
- m=0.2;
- file=fopen("test.txt","w");
- if (file!=NULL)
- {
- for (i=0;i<100000;i++)
- {while (z>=1.0)
- {
- x=2*rand()/(double)RAND_MAX-1;
- y=2*rand()/(double)RAND_MAX-1;
- z=pow(x,2)+pow(y,2);
- }
- w=m*x*sqrt(-2*log(z)/z)+n;
- fprintf(file,"%lf\n",w);
- z=2;
- }
- fclose(file);
- }
- printf("All done");
- return 0;
- }