Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 21st, 2012  |  syntax: None  |  size: 0.61 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. int main()
  6. {
  7.     FILE *file;
  8.     int i;
  9.     double n,m,w,x,y,z;
  10.     n=0.5;
  11.     m=0.2;
  12.     file=fopen("test.txt","w");
  13.     if (file!=NULL)
  14.     {
  15.         for (i=0;i<100000;i++)
  16.             {while (z>=1.0)
  17.             {
  18.                 x=2*rand()/(double)RAND_MAX-1;
  19.                 y=2*rand()/(double)RAND_MAX-1;
  20.                 z=pow(x,2)+pow(y,2);
  21.             }
  22.             w=m*x*sqrt(-2*log(z)/z)+n;
  23.             fprintf(file,"%lf\n",w);
  24.             z=2;
  25.             }
  26.             fclose(file);
  27.     }
  28.     printf("All done");
  29.     return 0;
  30. }