4 ms·
I think the section "Using normally distributed random numbers" deserves an additional explanation. The code may look simple, but like most of the other methods
by nayuki 8y ago
I think the section "Using normally distributed random numbers" deserves an additional explanation. The code may look simple, but like most of the other methods mentioned on the page, generating normally (Gaussian) distributed random numbers still requires the use of rejection sampling and sine/cosine functions. See https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform
- strainer 8y agoI implemented Marsaglia's Box Muller method in a library (^) and it seems quite quick. It doesn't involve trig functions, just a sqrt, a log, and an average of about two rands per normal outputted. It seems to work out around the same speed as a trig function - in javascript. For some purposes just averaging a few rands could be used to get a good enough approximation of a normal. I wonder if a short Taylor series could be mined that could quite accurately map equal to gaussian distribution. [^]http://strainer.github.io/Fdrandom.js/ http://strainer.github.io/Fdrandom.js/