Created
September 17, 2017 11:03
-
-
Save andersx/902eb7ab9e0d68e731009038ffdb9911 to your computer and use it in GitHub Desktop.
LOL
This file contains hidden or 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
| import numpy as np | |
| from numpy.random import uniform | |
| def simulate(probability): | |
| n = 1 | |
| while uniform() > probability: | |
| n += 1 | |
| return n | |
| if __name__ == "__main__": | |
| np.random.seed(666) | |
| size = 10000 | |
| probability = 0.1 | |
| samples = np.array([simulate(probability) for _ in xrange(size)]) | |
| print samples | |
| print samples.mean() | |
| print np.percentile(samples, 95) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment