Solved – Generating random numbers from normal distribution via inverse uniform distribution

normal distributionrandom-generationuniform distribution

I would like to create a random number generator for the normal distribution via using a uniform linear congruential generator (on uniform distribution) and the inversion method.

However, I'm getting stuck at the final state. Please correct my understanding at any point!

Say i have an LCG, which generates numbers from 0 – 1. It follows a uniform distribution of (0,1).

Now, I want my subsequent normal distribution (X) to follow the same range, so it's standard normal, hence i normalize the area

enter image description here

Now

enter image description here

Using taylor series as this cannot be integrated, I get

enter image description here

However, now I'm stuck. even if i integrate this, I cannot invert this to y = f(x) due to the powers of y. Am I even going about this right?

Any help will be much appreciated! thank you!

Best Answer

To sample from any distribution using uniform distribution you can use inverse transform method, so there is no need in re-inventing the wheel. For this you simply need to use inverse cumulative distribution function (also known as quantile function) of normal distribution

$$ F^{-1}(p) = \mu+\sigma\sqrt{2}\,\operatorname{erf}^{-1}(2p-1) $$

where $\operatorname{erf}$ is error function, and then take uniformly distributed random variable $U \sim \mathrm{Unif}(0, 1)$ and pass it through the quantile function

$$ X = F^{-1}(U) $$

resulting variable $X$ will follow normal distribution.

Most statistical software would provide you with quantile function for normal distribution already implemented (e.g. qnorm in R), but if you need to implement it by hand, you can check the following paper that describes algorithm that is used in R:

Wichura, M. J. (1988) Algorithm AS 241: The percentage points of the normal distribution. Applied Statistics, 37, 477–484.

or simply take a look at source code of R's qnorm.