Created
May 2, 2017 17:00
-
-
Save CherryDT/903b09434f50452918a02f1cfc34af7d to your computer and use it in GitHub Desktop.
Another way to stumble upon Euler and his weird and magical constant.
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
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