Last active
June 20, 2018 08:16
-
-
Save yishn/f6483ac4c6db268dfa43914b44fab8b1 to your computer and use it in GitHub Desktop.
Box-Muller transform
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
// Standard normal variate using Box-Muller transform | |
// https://en.wikipedia.org/wiki/Box-Muller_transform | |
function normalrand() { | |
let u = 0, v = 0; | |
while (u === 0) u = Math.random(); | |
while (v === 0) v = Math.random(); | |
return Math.sqrt(-2.0 * Math.log(u)) * Math.cos(2.0 * Math.PI * v); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment