Exercise 5.3.3
Suppose that instead of swapping element with a random element from the subarray , we swapped it with a random element from anywhere in the array:
PERMUTE-WITH-ALL(A) n = A.length for i = 1 to n swap A[i] with A[RANDOM(1,n)]
Does this code produce a uniform random permutation? Why or why not?
It does not. Intuitivelly, this one can go in different ways while there are combinations. Since does not divide , there is no way that this can be a uniform distribution. (Why doesn't it divide ? That's the intuitive part. is divisable by , but can't be for ).
Of course, this is a popular problem and there are tons of posts and papers written on it. Here's one from Coding Horror