# Generating random numbers from normal distribution via inverse uniform 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

Now

Using taylor series as this cannot be integrated, I get

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!

• Why not simply use inverse transform stats.stackexchange.com/questions/184325/… ?
– Tim
Sep 21 '16 at 14:36
• ...I was not aware such a magical function existed, thought I had to figure it out by hand. For curiositys sake, how would i compute this manually?
– Wboy
Sep 21 '16 at 14:43
• What you're trying to do is not a correct implementation of 'the inversion method'. Done correctly, you'd be trying to invert the normal cdf. Sep 21 '16 at 16:05
• No, you're not. There's several errors all at once which makes it hard to untangle. Sep 21 '16 at 16:12
• There's a graphical illustration of the inversion method for the normal case on the Wikipedia page Inverse transform sampling. Reading the article may help clarify ideas for you. Sep 21 '16 at 16:17

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.

• Thank you so much for your help! :) while that presents an alternative way, is there a way to do this via the method i mentioned? Namely, taking the range of the Uniform distribution, setting the distribution i want (standard norm) and normalizing it, attempting to integrate to get the cdf then invert etc?
– Wboy
Sep 21 '16 at 15:35