Assignment two optional correction

Sorry, but I made a mistake in writing down the shuffle algorithm. The probabilities are wrong. Some of you have been noticing the poor quality of the shuffling.

Here is the correct algorithm:

for (i = n - 1; i > 0; i--)
    exchange a[i] with a random element of 'a' at index from 0 to i inclusive

It is too late for me to change the assignment; thus you can use the original algorithm I stated.

But you can also use this one instead. This will yield a much better shuffling. And it's faster.

Sorry for the error.


[main course page]