Skip to content

Instantly share code, notes, and snippets.

@dasjestyr
Created August 26, 2013 21:07
Show Gist options
  • Save dasjestyr/6346680 to your computer and use it in GitHub Desktop.
Save dasjestyr/6346680 to your computer and use it in GitHub Desktop.
Fisher-Yates Shuffle
private static IEnumerable<Card> Shuffle(IList<Card> cards)
{
var rnd = new Random();
for (var n = cards.Count - 1; n > 0; --n)
{
var newPosition = rnd.Next(n + 1);
var temp = cards[n];
cards[n] = cards[newPosition];
cards[newPosition] = temp;
}
return cards;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment