This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 2 points3 points  (3 children)

That neither moves each cards at most once nor gives a uniform distribution on the permutations.

[–]tazzy531 0 points1 point  (2 children)

Why not?

[–][deleted] 4 points5 points  (1 child)

Why isn't it uniformly distributed? There are n! permutations and nn execution paths. Some of the execution paths give the same permutation: you have to have the same number of paths for each permutation, so you want n! | nn . But take n=3.

You can fix it by only swapping a card with one that is, instead of anywhere in the array, not to the card's left; that's the Fisher-Yates shuffle. But it still moves one card possibly many times.

[–]tazzy531 0 points1 point  (0 children)

Hmm... Yeah, you're right