
There was a question about ways of generating permutations: is there an easy way to show that these two functions: ### def permuteRestricted(L): newlist = L[:] # shallow copy for i in range(len(L)): rand_i = randint(i, len(L)-1) newlist[i], newlist[rand_i] = newlist[rand_i], newlist[i] return newlist def permuteUnrestricted(L): newlist = L[:] # shallow copy for i in range(len(L)): rand_i = randint(0, len(L)-1) rand_j = randint(0, len(L)-1) newlist[rand_j], newlist[rand_i] = newlist[rand_i], newlist[rand_j] return newlist ### act differently? I tried to prove this difference by brute force: the attached program generates the whole space of permutations, given these two methods. I have to apologize for the code's uglyness and sluggishness, and if anyone can simplify or optimize it, I'd be very happy. I hope this helps!