Statistics 6501, Winter 2002 1

Generating Normal Pseudo-random Numbers

Box-Muller Method:

How to simulate two independent Normal random variables with mean μ and variance σ^{2}?

Generating U, V independent UNIF (0, 1) random values.

Then

W = cos(2πU)\sqrt{−2ln(V)} and X = sin(2πU)\sqrt{−2ln(V)}

are such that W and X are independent Normal(0, 1) values.

To get Y and Z independent N(μ, σ^{2}) calculate

Y = μ + σW and Z = μ + σX

The following Pascal code implements the Box-Muller Method.

FUNCTION Random2 : Real;
{ This function checks if the random number we take the natural log  }
{ of is very small.  If so, then we set it equal to something small. }
VAR
      x : Real;
BEGIN
      x := Random;
      IF x <= 0.0001 THEN
            Random2 := 0.0001
      ELSE
            Random2 := x;
END;
PROCEDURE Normal(VAR W, X : REAL);
VAR
      T1, T2 : REAL;
BEGIN
      T1 := 2*Pi*Random;
      T2 := sqrt(-2.0*ln(Random2));
      W := cos(T1)*T2;               { Note W and X are independent }
      X := sin(T1)*T2;               { standard Normals.            }
END;