Random is barely random at all?

前端 未结 11 565
失恋的感觉
失恋的感觉 2020-11-27 10:27

I did this to test the randomness of randint:

>>> from random import randint
>>>
>>> uniques = []
>>> for i in range(4500         


        
11条回答
  •  無奈伤痛
    2020-11-27 10:35

    You are generating 4500 random numbers from a range 500 <= x <= 5000. You then check to see for each number whether it has been generated before. The birthday problem tells us what the probability is for two of those numbers to match given n tries out of a range d.

    You can also invert the formula to calculate how many numbers you have to generate until the chance of generating a duplicate is more than 50%. In this case you have a >50% chance of finding a duplicate number after 79 iterations.

提交回复
热议问题