Comment by hawthorns
5 days ago
It's dead simple. Here is the simplified version that returns the quantiles for '100 / 2 ~ 4'.
import numpy as np
def monte_carlo(formula, iterations=100000):
res = [formula() for _ in range(iterations)]
return np.percentile(res, [0, 2.5, \*range(10, 100, 10),
97.5, 100])
def uncertain_division():
return 100 / np.random.uniform(2, 4)
monte_carlo(uncertain_division, iterations=100000)
No comments yet
Contribute on Hacker News ↗