Skip to content

Instantly share code, notes, and snippets.

@telliott99
Created May 8, 2021 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save telliott99/50d8ffcded903763ac4f20f515b7b481 to your computer and use it in GitHub Desktop.
Save telliott99/50d8ffcded903763ac4f20f515b7b481 to your computer and use it in GitHub Desktop.
from matplotlib import pyplot as plt
import sys, random
N = int(sys.argv[1])
n = 100
L = list()
for i in range(N):
count = 0
prev = 0
while True:
r = random.random()
if count == 0:
count += 1
elif prev < r:
prev = r
count += 1
else:
L.append(count)
break
print(sum(L)/len(L))
'''
> p3 script.py 10000000
2.718501
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment