相关疑难解决方法(0)

随机几乎没有随意?

我这样做是为了测试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次.这是您从标准库中获得的最佳结果吗?

python random birthday-paradox

74
推荐指数
8
解决办法
4万
查看次数

如何在python中生成数组的排列?

我有一个27个元素的数组,我不想生成数组的所有排列(27!)我需要5000个随机选择的排列,任何提示将是有用的...

python permutation

26
推荐指数
4
解决办法
3万
查看次数

标签 统计

python ×2

birthday-paradox ×1

permutation ×1

random ×1