There are n objects in a list. N random numbers are generated, each pointing to a height in the list. Each time an object gets "hit", it gets 1 point.
What is the probability that an object gets: 1 point, 2 points, 3 points, etc.
I wrote a script that tests it. The result for 1 million objects, so, 36%, 18%, 6%, 1.5%, 0.3%, etc. How is this calculated mathematically? I asked this question, and it was closed, but there is no reason to close it.
population: 1000000
results:
1: 368282 , 36.8282 %
2: 184036 , 18.4036 %
3: 61046 , 6.1046000000000005 %
4: 15465 , 1.5465 %
5: 3009 , 0.3009 %
6: 519 , 0.0519 %
7: 56 , 0.0056 %
8: 11 , 0.0011 %
9: 1 , 0.000099 %
The script,
# cook your dish here
import math
import random
population = 10*6
registry = [0]population
count = []
for i in range(population):
randomNumber = random.randint(0, population-1)
registry[randomNumber] += 1
if len(count) < registry[randomNumber]: count.append(0)
for i in range(population):
if registry[i] != 0: count[registry[i]-1]+=1
print("population:", population)
print("results: ")
for i in range(len(count)):
print(i+1, ": ", count[i], ", ", count[i]/population*100, "%")
What do you mean by "with replacement" btw?
– Johan Jul 08 '21 at 14:423: 61046 , 6.1046000000000005 %but this is just supposed to be a ratio, $\frac{61046}{1000000}$ which is clearly $6.1046%$ exactly. Be careful with doing floating point arithmetic where it isn't necessary as it can cause oddities like this. See https://0.30000000000000004.com/ and this SO post. – JMoravitz Jul 08 '21 at 15:16