Programming | Statistics | Simulations

Get random numbers with normal (Gaussian) distributions from random numbers with uniform distributions

Especially relevant when programming with low-level languages that only simulate random numbers drawn from uniform distributions.

--

The core of “random” number generation by hardware is intrinsically tied to uniform (a.k.a. “even”, some call it “square”) distributions. However, for many applications, you’ll need random numbers drawn from other distributions.

I do a lot of programming for scientific applications, so I often need to simulate normally distributed errors and such. But low-level languages don’t include built-in functions for this, and many people just don’t even realize about it. That’s why I think this short article is important: to make you aware of the difference, and to explain how to transform the uniformly distributed numbers provided by generators into normally distributed numbers.

One common distribution is the Gaussian distribution (a.k.a. “normal”), which is useful for example to simulate most kinds of statistical noise in data. In this article I present general code to obtain normally distributed numbers from uniform distributions by using a very simple but efficient method, the Box-Muller Transform. I also provide ready-to-use JavaScript code, and an example where 6000 evenly distributed random…

--

--

LucianoSphere (Luciano Abriata, PhD)

https://www.lucianoabriata.com | Scientific writing, technology integrator, programming, biotech, bioinformatics.| Have a job for me? Contact me in ES FR EN IT