フィッシャー・イェーツのバリエーション

はい、rand() と仮定すると偶数分布です は。各入力が等しい確率で各順列を生成できることを示すことで、これを証明します。

N=2 は簡単に証明できます。子が各文字列を表すツリーとして描画します。カンマの後の文字を一番左の文字列に挿入することによって取得できます。

  0,1   //input where 0,1 represent indices
01  10  //output. Represents permutations of 01. It is clear that each one has equal probability

N の場合、N-1 のすべての順列があり、N の最後の文字をランダムに交換します

    (N-1 0th permutation),N     .....          (N-1 Ith permutation),N ________________________  
      /              \                       /                   \                             \ 
0th permutation of N  1st permutation....   (I*N)th permutation   ((I*N)+1)th permutation .... (I*N)+(I-1)th permutation

このくだらない誘導は、均等な分布をもたらすはずです。

例:

N=2:

  0,1
01  10 // these are the permutations. Each one has equal probability

N=3:

           0,1|2           // the | is used to separate characters that we will insert later
    01,2           10,2    // 01, 10 are permutations from N-1, 2 is the new value
 210 021 012   201 120 102 // these are the permutations, still equal probability

N=4:(読みやすいように曲げてあります)

                                                           0,1|23

                                                       01,2|3  10,2|3

                                           012,3 021,3 210,3    102,3 120,3 201,3

0123 0132 0321 3230                                                                                  2013 2031 2310 3012
                    0213 0231 0312 3210                                          1203 1230 1302 3201
                                        2103 2130 2301 3102  1023 1032 1320 3021

など