# C# # Great job, everyone. Here's my own answer in C# based on [the Fisher-Yates algorithm][1] (6 lines, for those keeping track). The idea is to partially sort the deck until `deck[0] == 0`. Once you know the value at that position, you can freely use it as a counter as long as you set it back to zero when you're done. Then, for each position `i` from 1 to 51, you swap `deck[i]` with `deck[rand(i, 51)]` (**not** rand(0, 51), that will throw off the randomness). Finally, set `deck[0]` back to zero and swap it with a random card. Should be a perfectly random shuffle. public static void shuffle(int[] deck) { while (deck[0] > 0) swap(ref deck[0], ref deck[deck[0]]); for (deck[0] = 1; deck[0] < 52; deck[0]++) swap(ref deck[deck[0]], ref deck[rand(deck[0], 51)]); deck[0] = 0; swap(ref deck[0], ref deck[rand(0, 51)]); } [1]: http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle