修改过的" Fisher-Yates是否会随机播放"实施保持随机?

时间:2015-03-07 08:26:10

标签: algorithm random shuffle

众所周知,Fisher–Yates shuffle给出了以下"现代算法"代码:

  To shuffle an array a of n elements (indices 0..n-1):
  for i from 0 to n − 1 do
       j ← random integer with **i** ≤ j < n
       exchange a[j] and a[i]

我的问题是:如果我在&#34;i≤j&lt; N'#34;到0,算法也会像上面的算法一样随机,如何证明?修改后的代码是:

  To shuffle an array a of n elements (indices 0..n-1):
  for i from 0 to n − 1 do
       j ← random integer with **0** ≤ j < n
       exchange a[j] and a[i]

0 个答案:

没有答案