That algorithm is certainly inefficient, but even so I don't think it should take 20 seconds for only 52 cards. Is something else going on that makes it worse? Perhaps the random number generator is biased against certain numbers and thus the last sweep will have an expected running time of more than O
?
-Q
-Q