# Use uniform distribution to generate standard normal distribution

As we all know, if $(x, y)$ is a pair of independent random variables that conform to the standard normal distribution, the joint probability density function can be formulated as:

$$ f(x, y) = \frac{1}{2\pi}e^{-\frac{x^2 + y^2}{2}}$$

Let’s set: $x = R\cos \theta, y = R \sin \theta$, the probability function of $R$ is:

$$P(R\leq r) = \int_{0}^{2\pi} \int_{0}^{r} \frac{1}{2\pi}e^{-\frac{-u^2}{2}} u du d\theta = \int_{0}^{r} e^{-\frac{u^2}{2}}u du = 1 - e^{-\frac{r^2}{2}}$$

We define $F_{R}(r) = P(R\leq r) = 1 - e^{-\frac{r^2}{2}}$, and set $F_{R}(r) = Z$, $R$ is obtained as the following:

$$R = F_{R}^{-1} (Z) = \sqrt{-2 \ln (1-Z)}$$

Note that $Z \in [0, 1] \rightarrow 1 - Z \in [0, 1]$.

Finally, we can replace $1-Z$ and $\theta$ with $U_1$ and $2\pi U_2$ where $U_1 \sim U(0, 1)$ and $U_2 \sim (0, 1)$ ($U_(a, b)$ represents uniform distribution range from $a$ to $b$). $U_1$ and $U_2$ are independant and conform to uniform distribution, $(x, y)$ can be formulated in the following way:

$$x = R\cos \theta = \sqrt{-2\ln U_1}\cos(2\pi U_2), y = R\sin \theta = \sqrt{-2\ln U_2}\sin(2\pi U_1)$$

Actually, this is a specialization of following conclusion:

The random number from any common distribution for which we know cumulative distribution function can be generated by a known uniform distribution.