from random import randrange trials = 10000 n = 50 totalpicks = 0 # total number of picks over all trials minpicks = None # smallest number of picks in a single trial maxpicks = None # biggest number of picks in a single trial for t in range(trials): # we will maintain list of n booleans such seen[k] = True # if we have collected coupon k for k in 0 to n-1. # Intially all are false seen = [False] * n # we will also keep track of how many distinct coupons we have # seen thus far, stopping once we have seen all n. distinct = 0 count = 0 while distinct < n: pick = randrange(n) count += 1 if not seen[pick]: seen[pick] = True distinct += 1 totalpicks += count if t == 0: # first trial minpicks = maxpicks = count else: minpicks = min(count, minpicks) maxpicks = max(count, maxpicks) print('Average number of picks', totalpicks/trials) print('Minimum number of picks', minpicks) print('Maximum number of picks', maxpicks)