Skip to content

Instantly share code, notes, and snippets.

@spoike
Created August 19, 2014 10:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spoike/eb1bd5ffc39b3167b8f2 to your computer and use it in GitHub Desktop.
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
/**
* 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