Skip to content
Oakfield Operator Calculus Function Reference Site

Box–Muller Gaussian Transform

The Box–Muller method maps two independent uniform samples on ((0,1)) to a pair of independent standard normal variables using logarithm, square root, and trigonometric transforms.

Z1=2lnU1cos(2πU2),Z2=2lnU1sin(2πU2)Z_1 = \sqrt{-2\ln U_1}\,\cos(2\pi U_2),\qquad Z_2 = \sqrt{-2\ln U_1}\,\sin(2\pi U_2)

Accepts uniform random inputs; outputs real-valued Gaussian samples with zero mean and unit variance.


The transform yields independent N(0,1)N(0,1) variables. The Jacobian ensures the correct density under ideal arithmetic; extremely small U1U_1 values are often clamped to avoid overflow in lnU1\ln U_1.


Fixing U2U_2 to a constant collapses the phase and destroys the rotational symmetry; the outputs are no longer Gaussian (e.g. U2=0U_2=0 gives Z2=0Z_2=0 and Z1=2lnU1Z_1=\sqrt{-2\ln U_1}, which is Rayleigh-distributed). Restricting to one output simply discards half of each uniform pair; each component is still N(0,1)N(0,1).


  • Using only Z1Z_1 discards half of each uniform pair.
  • Extremely small U1U_1 requires care due to lnU1\ln U_1.

Gaussian white noise uses the generated samples; inverse-CDF Gaussian sampling provides an alternative; the Marsaglia polar method avoids trigonometric evaluations while producing the same distribution.


Oakfield uses Box–Muller-style transforms internally when it needs Gaussian deviates from uniform RNGs:

  • White-noise stimuli (e.g. stimulus_white_noise) use Gaussian sampling to populate noise fields deterministically from a seed.
  • Stochastic operators (e.g. stochastic_noise) generate Gaussian sources for OU-style updates.
  • Integrator stochastic hooks use an internal RNG to generate Gaussian noise by default (with uniform/Laplace alternatives available).

The Box–Muller transform is a classic method for turning uniform random variables into Gaussian samples using an analytic change of variables.

While often superseded by faster methods in high-performance settings, it remains a standard reference implementation due to simplicity and exactness.


  • Box & Muller, “A Note on the Generation of Random Normal Deviates” (1958)
  • Devroye, Non-Uniform Random Variate Generation