Gaussian Normal Dist. Formula

• 03-05-2013
Michael Rupert
Gaussian Normal Dist. Formula
Hey guys, I'm writing a program to display a histogram of 1000 Gaussian distributed numbers. I've generated the numbers using rand and now need to transform them. I have found the following formula to use

f(x) = exp(-x^2 / (2*sigma^2)) / sqrt(2*pi*sigma)

and I am unsure how to implement this into a function.

Any help would be appreciated! Thanks.
• 03-05-2013
grumpy
The values returned by rand() typically approximate a uniform distribution. (Although the quality of implementation varies between libraries).

Google for techniques to convert a uniform distribution to a gaussian distribution. You will find plenty of information. It is not as simple as simply plugging in the formula you showed (which is the distribution function for a gaussian).
• 03-05-2013
Michael Rupert
I've come across the Box-Muller method, and it seems like the best way to do it, but to be honest, i'm not really sure how to apply that. A general over view of the process would help greatly.
• 03-05-2013
grumpy
First link to google with the string "box-muller" is this.

True, it doesn't provide code, but if your want to use the Box-Muller transform, the information is there. The mathematics is pretty simple.