Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><em>EDIT:</em> Since 12 August 2011 we have <a href="http://en.wikipedia.org/wiki/C++11" rel="nofollow noreferrer">C++11</a> which directly offers <a href="http://en.cppreference.com/w/cpp/numeric/random/normal_distribution" rel="nofollow noreferrer"><code>std::normal_distribution</code></a>, which is the way I would go today.</p> <p><em>Here's the original Answer:</em></p> <p>Here are some solutions ordered by ascending complexity.</p> <ol> <li><p><strong>Add 12 uniform numbers</strong> from 0 to 1 and subtract 6. This will match mean and standard deviation of a normal variable. An obvious drawback is that the range is limited to +/-6 - unlike a true normal distribution.</p></li> <li><p><strong>Box-Muller transform</strong> - was listed above, and is relatively simple to implement. If you need very precise samples however, be aware that the Box-Muller transform combined with some uniform generators suffers from an anomaly called Neave Effect. <p> H. R. Neave, “On using the Box-Muller transformation with multiplicative congruential pseudorandom number generators,” Applied Statistics, 22, 92-97, 1973</p></li> <li><p>For <strong>best precision</strong> I suggest <strong>drawing uniforms and applying the inverse cumulative normal distribution</strong> to arrive at normally distributed variates. You can find a very good algorithm for the inverse cumulative normal distribution at</p></li> </ol> <p><a href="https://web.archive.org/web/20151030215612/http://home.online.no/~pjacklam/notes/invnorm/" rel="nofollow noreferrer">https://web.archive.org/web/20151030215612/http://home.online.no/~pjacklam/notes/invnorm/</a></p> <p>Hope that helps</p> <p>Peter</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload