以下来自python网站,关于
random.shuffle(x[, random])
Shuffle the sequence
x
in place. The optional argument random is a 0-argument function returning a random float in[0.0, 1.0)
; by default, this is the functionrandom()
.Note that for even rather small
len(x)
, the total number of permutations ofx
is larger than the period of most random number generators; this implies that most permutations of a long sequence can never be generated.
如果我想重复获取 ['a'..'k']
的随机排列,似乎 shuffle 不会给我随机性。我的理解对吗?
谢谢!
最佳答案
You don't have anything to worry about.虽然 len(x)
低于 2000,但 random.shuffle
应该可以正常工作。
关于python random.shuffle的随机性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3160214/