Skip to content
All lessons

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

Read on blog.codinghorror.com
  • Algorithm
  • Optimization
  • Performance
  • Shuffle

Book a call

Lessons like this one
shape how we build.

Tell us what you’re building. In one call, we’ll show you how our team would approach it.

Tell us what you’re building, and we’ll show you how we’d approach it.

Still prefer the good old email? Contact us