The Box-Muller transform is a random number sampling method that converts
a pair of **uniformly distributed random numbers** into
a single (or if you'd rather, a pair^{1} of)
**normally distributed random number(s)**.

The default choices of the function definitions producing `r`

, `θ`

, and `n`

in this visualization produce a standard normal distribution.
Changing the functions can significantly alter the distribution of the transformed random numbers.
Play around with different combinations of functions to see how they affect the output.

Uniformly generate random values

Plot points (

`U₁`

,`U₂`

`∈`

`[0, 1]`

.
Plot points (

`U₁`

,`U₂`

) on the cartesian plane.
Click and drag to see a single point transform.

Project each point (

Define

Define

`U₁`

,`U₂`

) to a polar coordinate (`r`

, `θ`

).
Define

`r`

(the radial distance) as a function of `U₁`

.
Define

`θ`

(the angle from x axis) as a function of `U₂`

.
Click and drag to see a single point transform.

Define a function

Move the distribution center by changing the mean.

Widen or narrow the distribution by changing the stddev.

`f`

(`r`

, `θ`

) producing a scalar value `n`

.
Move the distribution center by changing the mean.

Widen or narrow the distribution by changing the stddev.

Click and drag to see the points that map to the range.

[1]
This transform can actually creates a **pair** of independent
and normally distributed values from the inputs `U₁`

and `U₂`

.
We consistently use the cosine function to create one value of the pair for this visualization.
The other value can be created by swapping cosine out for sine.