pioneerspacesim/pioneer — pull request #2651 by impaktor (2014-01-14 20:31:53+00:00)
Title: gaussian random number generator

## Random number with Gaussian distribution

Due to the central limit theorem, almost all random events have Gaussian
distribution, thus they are extremely handy.

### Semi Pull request / semi feature request.

I implemented the Box Muller method (from wikipedia). I'm unfamiliar with
exactly how the code is structured in Random.cpp and LuaRandom.cpp, but I
looked at the other code that was in place and guessed how it should be.

Please check if what I've done is sane, if it isn't then consider this is a
feature request, with code in place.

### Testing
It compiles, it runs, and it works. I put a in two for loops in DeliverPackage.lua:

-- Default to mean 0, and standard deviation 1.
for i=1,10000 do
print(Engine.rand:Normal())
end

and

-- Mean 4, standard deviation 2 (i.e. variance 4).
for i=1,1000 do
print(Engine.rand:Normal(4,2))
end

Plotting the result, it seems to work when comparing with the exact analytical form:

![gauss_normal](https://f.cloud.github.com/assets/619390/1914542/9c49edf2-7d59-11e3-8bb0-548d476d21d0.png)

![gauss_4_2](https://f.cloud.github.com/assets/619390/1914543/a4354e9e-7d59-11e3-8613-2efc4968f036.png)