I have tested several functions with the right configuration all work similarly and well.
http://jsfiddle.net/p3y40gf3/29/
Central limit is nice, must be with (n=3 for 6) and 12 for 12 to look as others. I configured others also to (6) or 12 or 1/12 as standard deviation, not sure why 12.
Central limit is a tiny bit less centered than Box/Muller and Ziggurat.
Box/Muller and Ziggurat look exactly the same
this variant by Joe(https://stackoverflow.com/a/33567961/466363) does standard deviation correctly:
function normal(mu, sigma, nsamples){ // using central limit
if(!nsamples) nsamples = 3
if(!sigma) sigma = 1
if(!mu) mu=0
var run_total = 0
for(var i=0 ; i<nsamples ; i++){
run_total += Math.random()
}
return sigma*(run_total - nsamples/2)/(nsamples/2) + mu
}
Ziggurat is also nice but needs to be adjusted from z score to from 0 to 1 looks like it makes good numbers.
Box/Muller clipped is good but gives few repeated numbers at clipped edges
but it is very similar to others,
incorrect random numbers should be discarded not clipped.
function randn_bm() {
var u = 0, v = 0;
while(u === 0) u = Math.random(); //Converting [0,1) to (0,1)
while(v === 0) v = Math.random();
let num = Math.sqrt( -2.0 * Math.log( u ) ) * Math.cos( 2.0 * Math.PI * v );
num = num / 6.0 + 0.5; // Translate to 0 -> 1 // changed here 10 to 6
if(num>1||num<0) return randn_bm(); return num; // bad random numbers should be discared not clipped
//return Math.max(Math.min(num, 1), 0); // cap between 0 and 1
}
Central limit variant it is called Bates distribution that is average
https://en.wikipedia.org/wiki/Bates_distribution
not confused with Irwin Hall that is a sum
https://en.wikipedia.org/wiki/Irwin%E2%80%93Hall_distribution
https://en.wikipedia.org/wiki/Normal_distribution#Generating_values_from_normal_distribution