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 pair1 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.
U₁,U₂ ∈ [0, 1].
U₁,U₂) on the cartesian plane.
U₁,U₂) to a polar coordinate (r, θ).
r (the radial distance) as a function of U₁.
θ (the angle from x axis) as a function of U₂.
f(r, θ) producing a scalar value n.
[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.