0

Possible Duplicate:
Implementing Box-Mueller random number generator in C#

I'm using a Box-Muller transform method to generate normally distributed random numbers:

 do {
        rand1 = 2*(rand()/(double)RAND_MAX)-1 ; 
        rand2 = 2*(rand()/(double)RAND_MAX)-1;
        distSqr = rand1 * rand1 + rand2 * rand2;
  } while (distSqr >= 1 );

  mp1 = sqrt((-2*log(distSqr))/distSqr); 
  res = rand1 * mp1;
  norm_dist=res*var+mean;

Is there an obvious mistake that I am making?

Community
  • 1
  • 1
straits
  • 315
  • 1
  • 4
  • 15

0 Answers0