Skip to content

Instantly share code, notes, and snippets.

@CherryDT
Created May 2, 2017 17:00
Show Gist options
  • Save CherryDT/903b09434f50452918a02f1cfc34af7d to your computer and use it in GitHub Desktop.
Save CherryDT/903b09434f50452918a02f1cfc34af7d to your computer and use it in GitHub Desktop.
Another way to stumble upon Euler and his weird and magical constant.
function estimateEulersConstant () {
const SAMPLES = 10000000;
let s = 0;
for (let n = 0; n < SAMPLES; n++) {
let x = 0;
let i = 0;
while (x < 1) {
x += Math.random();
i++;
}
s += i;
}
return s / SAMPLES;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment