# Math Help - Function generating normal distribted values?

1. ## Function generating normal distribted values?

Hi!

I have been thinking before of function generating a normal distributed value from a random number evenly distributed between 0 and 1, but I have given up and declared it impossible by using simple formulas.

Then yesturday, in a programming forum, a guy presented a code line to generate a normal distributed value with a simple formula! But not by using a random number, but by using two random numbers!

The formula looks like this:

$\mu\ + \sigma\cdot\sqrt{-2\log(r_1)}\cdot\sin(r_2 2\pi)$

where $\mu$ is the mean, $\sigma$ is the standard derivation, and $r_1,\ r_2$ is two random numbers both evenly distributed between 0 and 1. Supposably the logarithm is ment to be the natural logarithm.

I hav already found the square root to have the probability distribution function $f(x)\ =\ x\cdot e^{-\frac{x}{2}}$, and the sinus function to have the distribution function $g(x)\ =\ \frac{1}{2\pi\sqrt{1-x^2}}$, but now is the problem, what is the distributing function $h$ of the product of the square root and the sin function?

I wrote down the following formula, but I don't know if it's true:

$h(a)\ =\ \int_{-\infty}^{+\infty}f(x)\cdot g\left(\frac{a}{x}\right)\cdot\frac{a}{x^2}\cdot dx\ =\ \int_{-\infty}^{+\infty}g(x)\cdot f\left(\frac{a}{x}\right)\cdot\frac{a}{x^2}\cdot dx\$

Someone who knows if it is true? Is this some kind of cartesian product between distribution functions? And if it is true, is there any way to simplify the integral?

Edit: It should probably be a factor two of that, so:
$h(a)\ =\ 2\ \int_{-\infty}^{+\infty}f(x)\cdot g\left(\frac{a}{x}\right)\cdot\frac{a}{x^2}\cdot dx\ =\ 2\ \int_{-\infty}^{+\infty}g(x)\cdot f\left(\frac{a}{x}\right)\cdot\frac{a}{x^2}\cdot dx\$

2. Originally Posted by TriKri
Hi!

I have been thinking before of function generating a normal distributed value from a random number evenly distributed between 0 and 1, but I have given up and declared it impossible by using simple formulas.

Then yesturday, in a programming forum, a guy presented a code line to generate a normal distributed value with a simple formula! But not by using a random number, but by using two random numbers!

The formula looks like this:

$\mu\ + \sigma\cdot\sqrt{-2\log(r_1)}\cdot\sin(r_2 2\pi)$

where $\mu$ is the mean, $\sigma$ is the standard derivation, and $r_1,\ r_2$ is two random numbers both evenly distributed between 0 and 1. Supposably the logarithm is ment to be the natural logarithm.

I hav already found the square root to have the probability distribution function $f(x)\ =\ x\cdot e^{-\frac{x}{2}}$, and the sinus function to have the distribution function $g(x)\ =\ \frac{1}{2\pi\sqrt{1-x^2}}$, but now is the problem, what is the distributing function $h$ of the product of the square root and the sin function?

I wrote down the following formula, but I don't know if it's true:

$h(a)\ =\ \int_{-\infty}^{+\infty}f(x)\cdot g\left(\frac{a}{x}\right)\cdot\frac{a}{x^2}\cdot dx\ =\ \int_{-\infty}^{+\infty}g(x)\cdot f\left(\frac{a}{x}\right)\cdot\frac{a}{x^2}\cdot dx\$

Someone who knows if it is true? Is this some kind of cartesian product between distribution functions? And if it is true, is there any way to simplify the integral?

Edit: It should probably be a factor two of that, so:
$h(a)\ =\ 2\ \int_{-\infty}^{+\infty}f(x)\cdot g\left(\frac{a}{x}\right)\cdot\frac{a}{x^2}\cdot dx\ =\ 2\ \int_{-\infty}^{+\infty}g(x)\cdot f\left(\frac{a}{x}\right)\cdot\frac{a}{x^2}\cdot dx\$
Google for Box Muller transform or algorithm.

The idea is to generate (a,b) from a bivariate normal distribution, by
generating polar coordinates (r, theta) as r and theta are independent and
have distributions which are easily generated. Then converting to cartesians
to give two independent normally distributed RVs

RonL

3. So when you have got this kind of complicated integrals you know you're on the wrong track... Now I got it though. If the first distribution function I got is divided by the circumstance of a circle with radie x, it will be proportional to ordinary normal distrubution function. I saw that I had forgot a 2 in the formula, it should be $f(x)\ =\ x\cdot e^{-\frac{x^2}{2}}$.

Maybe the integrals could be solved if $x$ was substituted with $e^x$, but who cares anyway ^^

One more question about the normal distribution, why did one decide to use that formula to begin with? What's the background?

4. Originally Posted by TriKri
So when you have got this kind of complicated integrals you know you're on the wrong track... Now I got it though. If the first distribution function I got is divided by the circumstance of a circle with radie x, it will be proportional to ordinary normal distrubution function. I saw that I had forgot a 2 in the formula, it should be $f(x)\ =\ x\cdot e^{-\frac{x^2}{2}}$.

Maybe the integrals could be solved if $x$ was substituted with $e^x$, but who cares anyway ^^

One more question about the normal distribution, why did one decide to use that formula to begin with? What's the background?
It is important because it is the limiting form of the distribution of the
mean (and/or sum) of independent identically distributed random variables.
Which means that often in a system where the state is the result of a large
number of comparable disturbances on a deterministic process the observed
state will have a distribution close to normality.

One reason for this is the the Gaussian density is one of the distributions
which is its own Fourier transform (give or take a constant here or there).

RonL