Created
August 26, 2013 21:07
-
-
Save dasjestyr/6346680 to your computer and use it in GitHub Desktop.
Fisher-Yates Shuffle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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