for ( Src = 0; Src < N; Src++ )
{
   Dest = rand() % N;  // All N positions equally likely
   Swap (X[Src], X[Dest]);
}

Example 1: C++ implementation of shuffling algorithm that does not generate all permutations with equal probability.

Back to Article