我这样做是为了测试randint的随机性:
>>> from random import randint
>>>
>>> uniques = []
>>> for i in range(4500): # You can see I was optimistic.
... x = randint(500, 5000)
... if x in uniques:
... raise Exception('We duped %d at iteration number %d' % (x, i))
... uniques.append(x)
...
Traceback (most recent call last):
File "<stdin>", line 4, in <module>
Exception: We duped 887 at iteration number 7
Run Code Online (Sandbox Code Playgroud)
我尝试了大约10倍以上,我得到的最好结果是在转发器之前迭代了121次.这是您从标准库中获得的最佳结果吗?
我有一个27个元素的数组,我不想生成数组的所有排列(27!)我需要5000个随机选择的排列,任何提示将是有用的...