Skip to content

Instantly share code, notes, and snippets.

@andersx
Created September 17, 2017 11:03
Show Gist options
  • Select an option

  • Save andersx/902eb7ab9e0d68e731009038ffdb9911 to your computer and use it in GitHub Desktop.

Select an option

Save andersx/902eb7ab9e0d68e731009038ffdb9911 to your computer and use it in GitHub Desktop.
LOL
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