# Given only uniform distribution, using mathematical transformation to derive number draw from various distributions

If I only have a random number generator rand which generates a random number from a uniform distribution in [0,1], would it be possible to use some smart mathematical transformation to:

1. generate a value from a normal distribution with mean = 0 and variance = 1
2. generate a value from a poisson distribution with mean = 60

Thanks!

• You can always use the inverse function to the CDF. But there are better answers. Look up Box-Muller transformation for generating standard normal random variables. Also, there are fast approximate methods for approximating the Poisson CDF. – user10354138 Sep 14 '18 at 18:22

Write $$F(x) = P(X \leq x)$$ for the cumulative distribution function of the random variable you are trying to simulate. This is increasing so invertible. Take $Y = F^{-1}(U)$ where $U$ is your uniform random variable. Then $$P(Y \leq y)= P(F_X^{-1}(U) \leq y) = P(U \leq F_X(y)) = F_X(y) = P(X \leq y)$$ So the distribution of $Y$ is the same as that of $X$.

If $$U \sim \mathsf{Unif}(0,1)$$ and if random variable $$X$$ has inverse CDF (quantile function) $$F^{-1}_X(t),$$ then a realization $$u$$ of $$U$$ produces a realization $$F^{-1}_X(u)$$ of $$X.$$

For example, if $$X \sim \mathsf{Exp}(1),$$ then we have PDF $$f_X(x) = e^{-x},$$ CDF $$F_X(x) = 1 - e^{-x},$$ and quantile function $$F_X^{-1}(t) = -\log(1-t),$$ for $$x > 0, 0 < t < 1).$$ Thus if you generate a sample of size 10,000 from $$U \sim \mathsf{Unif}(0, 1),$$ then $$X = -\log(1 - U) \sim \mathsf{Exp}(1).$$

This can be demonstrated in R statistical software as shown below. [In R, runif generates a sample from a uniform distribution and dexp is an exponential PDF.]

set.seed(917);  u = runif(10^4);  x = -log(1-u)
summary(u)
Min.  1st Qu.   Median     Mean  3rd Qu.     Max.
0.000243 0.280017 0.677848 0.981355 1.363933 7.717536

hist(x, prob=T, col="skyblue2")
curve(dexp(x), 0, 8, add=T, col="red", lwd=2, n = 10001)


In the figure below, the histogram shows the 10,000 simulated values $$X$$ and the curve is the density of $$\mathsf{Exp}(1).$$

This 'quantile method' works easily if the CDF of $$X$$ can be written in closed form and then inverted to find the quantile function of $$X.$$ The idea can often be extended more widely by finding a rational approximation of the CDF and inverting it.

In R, a random sample of size n from a standard unform distribution can be generated with rnorm(n) which is (a few technical details for optimization notwithstanding) essentially qnorm(runif(n)), where qnorm uses Michael Wichura's rational approximation to the normal quantile function. (The approximation is accurate to the degree that can be represented by double precision arithmetic.)

set.seed(918);  z = qnorm(runif(10^5))
summary(z)
Min.   1st Qu.    Median      Mean   3rd Qu.      Max.
-4.283920 -0.673689  0.004902  0.005624  0.683117  4.532156


An entirely different method, specific to normal distributions, is used by the 'Box-Muller transformation' which generates two standard normal variates from two standard uniform ones. [One nice explanation is given in Wikipedia.]