Created
November 1, 2017 09:20
-
-
Save tail-call/26ae88c458ba58e5ba0390c24c768ed1 to your computer and use it in GitHub Desktop.
Get normally distributed random value
This file contains 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
// From <https://github.com/ondras/rot.js/blob/master/src/rng.js> | |
// I have no idea how this works | |
function getNormal (mean, stddev) { | |
do { | |
var u = 2*this.getUniform()-1; | |
var v = 2*this.getUniform()-1; | |
var r = u*u + v*v; | |
} while (r > 1 || r == 0); | |
var gauss = u * Math.sqrt(-2*Math.log(r)/r); | |
return (mean || 0) + gauss*(stddev || 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From what I get, Box–Muller transform is utilized.