Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Algorithm 生成均匀随机排列_Algorithm - Fatal编程技术网

Algorithm 生成均匀随机排列

Algorithm 生成均匀随机排列,algorithm,Algorithm,我不确定以下伪代码是否可以生成一致随机排列: PERMUTATE(A): n = A.length for i = 1 to n swap A[i] and A[random(1,n)] 这似乎是对的,但有人能给我一个严格的证据来验证它的正确性或错误性吗?这个解决方案是有偏见的,你想要[这是类似的]非偏见排列。[基本上,您需要使用random(i,n)而不是random(1,n)] 讨论您的解决方案有偏差的方式和原因

我不确定以下伪代码是否可以生成一致随机排列:

PERMUTATE(A): 
    n = A.length
    for i = 1 to n
        swap A[i] and A[random(1,n)]

这似乎是对的,但有人能给我一个严格的证据来验证它的正确性或错误性吗?

这个解决方案是有偏见的,你想要[这是类似的]非偏见排列。[基本上,您需要使用
random(i,n)
而不是
random(1,n)
]

讨论您的解决方案有偏差的方式和原因