St · Statistics & Probability

Why Does the Marsaglia Polar Method Generate Standard Normals?

Published By the 9to5Science editorial team

At a glance

  1. 1. Draw two uniforms

    Choose U and V independently and uniformly from the interval from minus one to one.

  2. 2. Keep points in disk

    Compute S = U squared plus V squared; reject unless zero is less than S and S is less than one.

  3. 3. Transform the point

    Multiply both coordinates by the square root of minus two times the natural log of S, divided by S.

  4. 4. Read the outputs

    The transformed coordinates are independent standard normal random variables.

The Marsaglia polar method generates normal random variables from uniform ones by rejecting some pairs and transforming the rest. Its key is that accepted points are uniformly distributed in a disk. The point’s angle supplies a uniform direction, while a transformation of its distance from the origin supplies exactly the radial distribution of a two-dimensional standard normal.

The method

Draw UU and VV independently and uniformly from (−1,1)(-1,1), then calculate

S=U2+V2.S=U^2+V^2.

If S=0S=0 or S≥1S\geq 1, reject the pair and draw another. Otherwise, set

M=−2ln⁡SS,X=UM,Y=VM.M=\sqrt{\frac{-2\ln S}{S}},\qquad X=UM,\qquad Y=VM.

The pair (X,Y)(X,Y) consists of two independent standard normal random variables. Some implementations start with uniforms on [0,1)[0,1) and convert them using U=2A−1U=2A-1 and V=2B−1V=2B-1. The endpoints do not affect the distribution because individual endpoints have probability zero.

Why the accepted point is uniform in the disk

Before rejection, (U,V)(U,V) is uniform in the square (−1,1)2(-1,1)^2: its density is constant there. Conditioning on the event 0<S<10<S<1 restricts this constant density to the unit disk. Thus, given that a pair is accepted, its location is uniform in that disk.

Write the point in polar coordinates as (ρ,Θ)(\rho,\Theta), where ρ=S\rho=\sqrt{S}. For 0<s<10<s<1, the probability that S≤sS\leq s, conditional on acceptance, is the ratio of the area of a disk of radius s\sqrt{s} to the area of the unit disk:

Pr⁡(S≤s∣0<S<1)=π(s)2π=s.\Pr(S\leq s\mid 0<S<1)=\frac{\pi(\sqrt{s})^2}{\pi}=s.

Therefore SS is uniform on (0,1)(0,1). The angle Θ\Theta is uniform on [0,2π)[0,2\pi) and independent of SS, because the disk is rotationally symmetric and the density is constant.

The probability of accepting one proposed pair is the ratio of the unit disk’s area to the square’s area:

Pr⁡(0<S<1)=π4.\Pr(0<S<1)=\frac{\pi}{4}.

Rejection changes how many proposals the algorithm needs, but not the conditional distribution of an accepted point.

Why the transformed radius is normal

The transformation multiplies the original point by the positive factor MM. It leaves its angle unchanged. Since the original radius is ρ=S\rho=\sqrt{S}, the new radius is

R=ρM=S−2ln⁡SS=−2ln⁡S.R=\rho M=\sqrt{S}\sqrt{\frac{-2\ln S}{S}}=\sqrt{-2\ln S}.

For r≥0r\geq 0, the distribution of this radius follows from S∼Uniform⁡(0,1)S\sim\operatorname{Uniform}(0,1):

Pr⁡(R>r)=Pr⁡ ⁣(S<e−r2/2)=e−r2/2.\Pr(R>r)=\Pr\!\left(S<e^{-r^2/2}\right)=e^{-r^2/2}.

Differentiating gives the radius density fR(r)=re−r2/2f_R(r)=r e^{-r^2/2} for r≥0r\geq 0. Together with the independent uniform angle, this is the polar-coordinate distribution of a bivariate standard normal. In polar coordinates its density is

fR,Θ(r,θ)=12πre−r2/2,r≥0,  0≤θ<2π.f_{R,\Theta}(r,\theta)=\frac{1}{2\pi}r e^{-r^2/2},\qquad r\geq 0,\;0\leq\theta<2\pi.

To convert from polar coordinates to Cartesian coordinates, divide by the Jacobian factor rr. The resulting joint density is

fX,Y(x,y)=12πe−(x2+y2)/2=(12πe−x2/2)(12πe−y2/2).f_{X,Y}(x,y)=\frac{1}{2\pi}e^{-(x^2+y^2)/2} =\left(\frac{1}{\sqrt{2\pi}}e^{-x^2/2}\right) \left(\frac{1}{\sqrt{2\pi}}e^{-y^2/2}\right).

Each factor is the density of a standard normal variable, and the joint density factors into the product of the two marginal densities. That factorization proves both that XX and YY are standard normal and that they are independent.

A numerical example

Suppose a proposed pair is U=0.3U=0.3 and V=0.4V=0.4. Then

S=0.32+0.42=0.25,S=0.3^2+0.4^2=0.25,

so the point is accepted. The multiplier is

M=−2ln⁡(0.25)0.25≈3.3302.M=\sqrt{\frac{-2\ln(0.25)}{0.25}}\approx 3.3302.

The output is approximately X=0.9991X=0.9991 and Y=1.3321Y=1.3321. A single output pair does not demonstrate the distribution; the proof comes from the distribution of the accepted radius and angle. This calculation simply shows how an accepted point is transformed.

Common mistakes

  • Keeping points outside the disk: Reject when S≥1S\geq 1. The proof relies on the accepted points being uniform in the unit disk, not in the whole square.
  • Forgetting to reject S=0S=0: The formula divides by SS and involves ln⁡S\ln S. This case has probability zero in exact sampling, but an implementation should reject it.
  • Using the wrong multiplier: The factor is −2ln⁡(S)/S\sqrt{-2\ln(S)/S}. Omitting the division by SS fails to cancel the original radius S\sqrt S.
  • Confusing the two coordinates: A single accepted pair produces two independent standard normal values. If you use only one, the other is still a valid normal draw; it is often more efficient to retain both.
  • Treating the acceptance rate as a normality condition: The rate π/4\pi/4 measures efficiency, not correctness. Correctness comes from the conditional distribution of accepted points and the radius transformation.

In finite-precision arithmetic, the method is implemented with pseudorandom numbers rather than ideal continuous uniforms. The mathematical result describes the ideal algorithm; practical output accuracy also depends on the quality of the random-number generator and numerical implementation.

References

  1. G. Marsaglia and T. A. Bray, “A Convenient Method for Generating Normal Variables,” SIAM Review, 6(3), 260–264 (1964).

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.