Possible Duplicate:
What distribution do you get from this broken random shuffle?
This is from Skiena's Algorithm Design Manual.
Assume that myrand(a, b) generates a random number between a and b inclusive.
The following code generates permutations uniformly at random
for(int i = 0; i < n; i++)
swap( a[i], a[myrand(i, n-1)]);
whereas the following doesn't.
for(int i = 0; i < n; i++)
swap( a[i], a[myrand(0, n-1)]);
The question is, why?