Created
August 19, 2014 10:55
-
-
Save spoike/eb1bd5ffc39b3167b8f2 to your computer and use it in GitHub Desktop.
Generate uniform (normal distributed) random numbers. Taken from http://www.protonfish.com/random.shtml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Generates normally distributed random numbers | |
*/ | |
function normalRandom(mean, stdDev) { | |
// Generate a "close enough" uniform random | |
// number w. mean = 0 and std.dev = 1 | |
var uniformRandom = (Math.random()*2-1)+(Math.random()*2-1)+(Math.random()*2-1); | |
return Math.round(uniformRandom * stdDev + mean); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment