关于Random Shuffling算法。

其实就是随机洗牌。

Knuth给过一个算法,为代码如下:

注意:随机数不是1~n,而是i~n!!

For i = 1 to n
    Pick a random integer j from i to n
    Swap A[i] and A[j]

关于为什么如此,吾等码农就不了解了,等大神来证明吧……

One thought on “关于Random Shuffling算法。

Leave a Reply

Your email address will not be published. Required fields are marked *