Skip to content

Box–Muller transform

The Box–Muller transform turns two independent uniforms into two independent standard normals. Follow the radius-angle construction, its density proof and the zero-input trap.

The Box–Muller transform converts two independent uniform random variables into two independent standard normal random variables. It supplies Gaussian shocks for Monte Carlo simulation, including the normal increments used to simulate diffusion models in option pricing. The transformation determines the output distribution; it does not create a good random-number source from a poor one.

Its useful surprise is that a pair of bell-shaped coordinates is easier to construct through a radius and an angle than through either coordinate's cumulative distribution function.

Two uniforms, two normal coordinates

Let U1,U2U_1,U_2 be independent, each with the continuous uniform distribution on (0,1)(0,1). Set
R=−2ln⁡U1,Θ=2πU2,R=\sqrt{-2\ln U_1},\qquad \Theta=2\pi U_2,

then return

Z1=Rcos⁡Θ,Z2=Rsin⁡Θ.Z_1=R\cos\Theta,\qquad Z_2=R\sin\Theta.
Both outputs have the standard normal distribution, N(0,1)\mathcal{N}(0,1), and they are independent random variables. Angles are in radians; the logarithm is natural. All variables in this construction are dimensionless.

To obtain a normal variable with mean μ\mu and standard deviation σ>0\sigma>0, use X=μ+σZ1X=\mu+\sigma Z_1. The second argument in N(μ,σ2)\mathcal{N}(\mu,\sigma^2) is the variance, so it is σ\sigma, rather than σ2\sigma^2, that multiplies the generated shock.

One fixed pair to check the arithmetic

Choose the stipulated demonstration inputs
u1=e−2,u2=18.u_1=e^{-2},\qquad u_2=\frac18.

These are chosen numbers, not an observed random sample. They give

r=2,θ=π4,z1=z2=2≈1.414214.r=2,\qquad \theta=\frac{\pi}{4},\qquad z_1=z_2=\sqrt2\approx1.414214.

The identity z12+z22=4z_1^2+z_2^2=4 checks the radius. The equal positive coordinates check the first-quadrant angle. Two outputs being equal in this constructed example says nothing about dependence across random draws; independence is a property of the joint probability law.

Stipulated uniforms exp(−2) and 1/8 produce radius 2, angle pi/4 and coordinates (square root of 2, square root of 2). The theoretical radial tail at radius 2 is 13.53%, distinct from a one-coordinate normal tail.
Stipulated uniforms exp(−2) and 1/8 produce radius 2, angle pi/4 and coordinates (square root of 2, square root of 2). The theoretical radial tail at radius 2 is 13.53%, distinct from a one-coordinate normal tail.
Original exact construction and theoretical radial survival law, with no simulated observations. The point uses stipulated inputs; the curve describes the ideal random-input model.

Why the shared radius does not destroy independence

For r≥0r\ge0, reversing the decreasing logarithmic transformation gives

P(R>r)=P(U1<e−r2/2)=e−r2/2.\mathbb{P}(R>r) =\mathbb{P}(U_1<e^{-r^2/2}) =e^{-r^2/2}.
Thus RR has density fR(r)=re−r2/2f_R(r)=r e^{-r^2/2} for r>0r>0. The radius is not normally distributed. Its square has an exponential distribution with rate 1/21/2. The angle is uniform over a full turn and independent of the radius, because each comes from a different independent input.

The joint radius-angle density is therefore

fR,Θ(r,θ)=r2πe−r2/2,r>0,0<θ<2π.f_{R,\Theta}(r,\theta) =\frac{r}{2\pi}e^{-r^2/2}, \qquad r>0,\quad 0<\theta<2\pi.

The polar-to-Cartesian Jacobian determinant has absolute value rr. Dividing by this area factor yields the output density, apart from irrelevant sets of area zero:

fZ1,Z2(x,y)=12πe−(x2+y2)/2=(e−x2/22π)(e−y2/22π).\begin{aligned} f_{Z_1,Z_2}(x,y) &=\frac{1}{2\pi}e^{-(x^2+y^2)/2}\\ &=\left(\frac{e^{-x^2/2}}{\sqrt{2\pi}}\right) \left(\frac{e^{-y^2/2}}{\sqrt{2\pi}}\right). \end{aligned}
That factorisation establishes two standard normal marginals and independence, rather than merely zero correlation. This is the geometric argument formalised in Vihola's Theorem 2.10.

If you instead hold RR fixed at a positive value, the coordinates are constrained to one circle and are dependent. Box–Muller uses a random radius with exactly the law above; the fixed-radius conditional picture is a different distribution.

The boundary matters in actual software

The continuous model assigns probability zero to any exact endpoint. A finite-state generator may nevertheless return exactly zero. Substituting u1=0u_1=0 makes ln⁡u1\ln u_1 undefined. Use a documented positive-uniform convention or redraw a zero radial input; silently replacing zero with an arbitrary small constant changes the tail behaviour. Zero is harmless for the angle input. The deterministic boundary u1=1u_1=1 gives radius zero.

Finite precision also means a generator cannot reproduce an unbounded continuous Gaussian law exactly: its smallest positive radial uniform bounds the attainable radius. That implementation limit does not mean the mathematical normal distribution has bounded support.

The Marsaglia polar method is a related rejection algorithm that avoids sine and cosine; it is a distinct procedure, not the trigonometric formula above. For a broader treatment, the Random Number Generation lesson covers both constructions and inversion. The full lesson requires membership; a public preview is available.

In production simulations, use a tested normal generator and record its seed and algorithm for reproducibility. Generating correct Gaussian shocks validates one ingredient of a model; it does not establish that market returns are Gaussian or that a discretised pricing model is accurate.

Sources

Last updated
  • simulation
  • normal generation
  • uniform distribution
  • change of variables
  • independence
  • finite precision
← Back to the glossaryBack to top ↑