There seems to be nowhere on the internet that has code for a random number generator for JavaScript that does normal (Gaussian) distribution of values. You may remember this distribution as the ‘bell curve’ from school. This is really cool for picking random numbers that don’t distribute linearly. Using the Box-Muller transform seems to be the best way to do this in the real world, so I wrote a little function that will do it for you in JavaScript
Enjoy!
Math.nrand = function() { var x1, x2, rad; do { x1 = 2 * this.random() - 1; x2 = 2 * this.random() - 1; rad = x1 * x1 + x2 * x2; } while(rad >= 1 || rad == 0); var c = this.sqrt(-2 * Math.log(rad) / rad); return x1 * c; };

