# The Azimuth Project Transforming uniform random variables to other distributions (Rev #5, changes)

Showing changes from revision #4 to #5: Added | Removed | Changed

# Transforming uniform random variables to other distributions

## Idea

It is common to have a low-level Random number generator which generates uniform variates on $[0,1)$ and generate variates from other distributions by “processing” those variables. One very flexible but memory-intensive approach is to use look-up tables to convert them. For some distributions a simpler mathematical transformation method can be used. We list some of the most common below. In what follows, lowercase letters denote pseudo-random numbers on $[0,1)$.

### Normal distribution

1. Generate $u$ and $v$ and set $U=2u-1$, $V=2v-1$.
2. Set $W=U^2+V^2$. If $W \gt 1$ restart from 1.
3. Set $A=\sqrt{(-2\log W)/W}$.
4. Values $T_1=U A$ and $T_2=V A$ are two independent variates from the Normal/Gaussian distribution.

### Multivariate normal distribution

1. Use the above method to generate $N$ independent standard normal random numbers (samples from $N(0,1)$), forming an $N$-vector $X$.
2. Set  V = LX L X + \mu, where $L$ is the left Cholesky factor of the multivariate normal covariance matrix $\Sigma$ ( \Sigma\equiv LL^T L L^T), and $\mu$ is the multivariate normal mean vector. The vector $V$ is a random sample from the distribution $N(\mu,\Sigma)$.

### Student-$t$ distribution with $n$ degrees of freedom

1. Generate $u$ and $v$ and set $U=2u-1$, $V=2v-1$.
2. Set $W=U^2+V^2$. If $W \gt 1$ restart from 1.
3. Value $T=U\sqrt{n \frac{W^{-2/n}-1}{W}}$ is from the Student-$t$ distribution with $n$ degrees of freedom.

### Cauchy distribution

1. Generate $u$ and $v$ and set $U=2u-1$, $V=2v-1$.
2. Set $W=U^2+V^2$. If $W \gt 1$ restart from 1.
3. Value $T=U\sqrt{\frac{W^{-2}-1}{W}}$ is from the Cauchy distribution.

### Exponential distribution

1. Generate $u$, then $\frac{\exp u}{\lambda}$ is form the $Exp(\lambda)$ distriubtion.

### Gamma$(n,\lambda)$ distribution

1. Generate $n$ variates $V_1$ to $V_n$ from $Exp(\lambda)$ using the above method.
2. Then $V_1+\dots +V_N$ is from the Gamma$(n,\lambda)$ distribution.

• TODO