Created
July 16, 2021 19:41
-
-
Save cesarvargas00/11a0a9e4f0a8c3397aaba30edc2d53fd to your computer and use it in GitHub Desktop.
twitter question
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 empirical(x, y, n){ | |
for (let i = 0; i < n; i++){ | |
x = x * (1 + (Math.random() < .5 ? -1 : 1) * (Math.random() * y)/x) | |
} | |
return x | |
} | |
let xs = [] | |
for (let i = 0; i < 10000; i++){ | |
xs.push(empirical(100, 1, 10000) | |
) | |
} | |
xs.reduce((acc, x) => acc + x,0)/xs.length |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment