shuffling

algorithms

The Danger of Naïveté

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'

By Jeff Atwood ·
Comments

arrays

Shuffling

Pop quiz, hotshot. How would you write code to shuffle a deck of cards? I was thinking about this after reading Mike's card-shuffling algorithm woes: Here's where the non-CS mind comes into play. My first thought was to generate an unshuffled deck as an array-like structure

By Jeff Atwood ·
Comments