Skip to content

Instantly share code, notes, and snippets.

@yishn
Last active June 20, 2018 08:16
Show Gist options
  • Save yishn/f6483ac4c6db268dfa43914b44fab8b1 to your computer and use it in GitHub Desktop.
Save yishn/f6483ac4c6db268dfa43914b44fab8b1 to your computer and use it in GitHub Desktop.
Box-Muller transform
// 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