Created
April 3, 2017 21:31
-
-
Save olehermanse/21a2ec61ffad713781a60e9b464f9839 to your computer and use it in GitHub Desktop.
Average number of tries to pick all options
This file contains 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.random as random | |
attempts = 100000 | |
choices = 25 | |
def one_test(possibilities): | |
found = [] | |
num = 0 | |
while len(found) < possibilities: | |
r = random.randint(1,possibilities) | |
if r not in found: | |
found.append(r) | |
num += 1 | |
return num | |
results = [] | |
for i in range(attempts): | |
results.append(one_test(choices)) | |
print("Average over {} runs: {}".format(attempts, sum(results)/attempts)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment