mercredi 4 février 2015

Probability seems wrong using Python randint

I'm using Python 2.7 to generate two random numbers, both 1-100 (including 1 and 100), and if they are the same, an event occurs. I would think that the probability of this would be 1/10000 because


1/100 x 1/100 = 1/10000


but the number times that it takes for the two numbers to match up is usually between 10-200. Why does this happen and is there any way to fix it?




Here's my full code:



import random
p5SickGen1 = random.randint(1,100)
p5SickGen2 = random.randint(1,100)
counter = 0
while p5SickGen1 != p5SickGen2:
counter += 1
p5SickGen1 = random.randint(1,100)
p5SickGen2 = random.randint(1,100)

print(counter)




Aucun commentaire:

Enregistrer un commentaire