Skip to content

Instantly share code, notes, and snippets.

@cesarvargas00
Created July 16, 2021 19:41
Show Gist options
  • Save cesarvargas00/11a0a9e4f0a8c3397aaba30edc2d53fd to your computer and use it in GitHub Desktop.
Save cesarvargas00/11a0a9e4f0a8c3397aaba30edc2d53fd to your computer and use it in GitHub Desktop.
twitter question
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