Skip to content

Instantly share code, notes, and snippets.

@fuddl
Last active October 13, 2015 08:47
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 fuddl/4169785 to your computer and use it in GitHub Desktop.
Save fuddl/4169785 to your computer and use it in GitHub Desktop.
Gaussian normal distribution
/**
* Generate a random number considering gaussian normal distribution.
*
* @param min
* The minimal value. Can be negative or positive.
*
* @param max
* The maximal value. Should be higher then min.
*
* @param dis
* The distribution. The higher is value is, the less likely min or max will
* be directly returned.
*
* @return
* A random number between min and max respecting the normal distribution.
*/
function normalRand(min, max, dis) {
var dis = typeof dis !== 'undefined' ? dis : 42;
var o = 0;
var delta = max - min;
for(var i = 0; i < dis; i++) {
o += Math.random()*delta+min
}
o = Math.round(o / dis);
return o;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment