vendredi 10 novembre 2023

Subtracting random number does not match average I should get

Suppose you organize a competition with 25 million participants. At each round, a random number from the people remaining is eliminated. How many rounds should we expect to get 5 participants or less ? Now 25M/2^22 is the closest number higher than 5 so 22 rounds on average. However, when verifying this in Python, I get that the distribution is more accumulated around 15-16 rather than 22-23. (I am not very familiar with Python so I know I should use dictionaries to count stuff etc.) Is there a mistake in my code ? Because theory cannot lie.

import random

lst=list()
for j in range(1,10000):
    i=0
    X=25000000
    while X > 5:
        i = i+1
        elim=(random.randint(0,X))
        X = X - elim
    lst.append(i)
    
for i in range(1,33):
    print( i, "appears", lst.count(i), "times")

print("22 appears", lst.count(22)*100/len(lst), "% of the time")
print("15 appears", lst.count(15)*100/len(lst), "% of the time")



Aucun commentaire:

Enregistrer un commentaire