Tech Insights· blog.codinghorror.com
Fisher-Yates: the best way to shuffle an array and the dangers of naïveté
From blog.codinghorror.com
In my previous post on shuffling, I glossed over something very important. The very first thing that came to mind for a shuffle algorithm is this: for (int i = 0; i < cards.Length; i++) { int n = rand.Next(cards.Length); Swap(ref cards[i], ref cards[n]); } It’s a
Shared by
- Algorithm
- Optimization
- Performance
- Shuffle



