Back to Blog
Technology7 min readMay 6, 2026

The Fisher-Yates Shuffle Explained Simply

The algorithm behind every fair shuffle — from professional lotteries to RandomLists.app. Here is how it works, why it is perfect, and why naive shuffles fail.

Every time you shuffle a deck of cards, flip a coin, or draw a name from a hat, you are performing a randomization. But not all randomizations are created equal. Some shuffling methods look random but contain hidden patterns. Others are genuinely uniform — meaning every possible outcome is equally likely. The difference matters enormously in high-stakes contexts like lotteries, scientific studies, and fair selection processes.

The Fisher-Yates shuffle is the gold standard for generating a genuinely uniform random permutation of a list. It is the algorithm used by professional lottery systems, scientific randomization software, and — if they are done correctly — every reputable digital random picker on the web, including RandomLists.app.

The good news is that despite its impressive credentials, the Fisher-Yates shuffle is conceptually simple. You do not need a computer science degree to understand how it works or why it is better than alternatives. You just need a list and a fair source of randomness.

The Problem With Naive Shuffling

Before explaining Fisher-Yates, it helps to understand why naive shuffling methods fail. Imagine you want to shuffle a list of five items: A, B, C, D, E. A simple approach might be: for each item, swap it with a randomly chosen item from the entire list.

This sounds reasonable. But it produces a non-uniform distribution — some orderings of the list will appear more often than others. The reason is mathematical: when you allow each item to potentially swap with any other item (including itself, multiple times), the probability tree becomes unbalanced. There are 5! = 120 possible orderings of five items, but the naive algorithm generates them with unequal probabilities.

This is not a theoretical concern. In 2010, Microsoft's Bing voting system used a naive shuffle to randomize candidate options and was caught producing non-uniform results. The bias was statistically detectable. In any context where fairness matters — drawing contest winners, randomizing test questions, assigning clinical trial participants — a biased shuffle is a real problem.

How Fisher-Yates Works

The Fisher-Yates algorithm was first described by Ronald Fisher and Frank Yates in their 1938 book "Statistical Tables for Biological, Agricultural and Medical Research." The modern version, adapted for computers by Richard Durstenfeld in 1964, works as follows:

Start with your list of n items. Pick a random number between 1 and n. Swap the item at that position with the last item in the list. Now treat the last item as "done" — exclude it from future swaps. Repeat: pick a random number between 1 and n-1, swap that item with the second-to-last item. Continue until you have processed every item.

Let us trace through a small example. Suppose your list is [A, B, C, D]. Step one: pick a random position between 1 and 4. Say we pick 3 (item C). Swap C with D: [A, B, D, C]. C is now fixed at the end. Step two: pick a random position between 1 and 3. Say we pick 1 (item A). Swap A with D: [D, B, A, C]. A is now fixed. Step three: pick a random position between 1 and 2. Say we pick 2 (item B). Swap B with D: [D, B, A, C] — wait, B is already in position 2, so no effective swap. [D, B, A, C]. One item remains. The final shuffle is [D, B, A, C].

The key insight is that each item is placed exactly once, in a randomly chosen remaining position. Because of this structure, every permutation of the list is exactly equally likely. The mathematics are clean and provable.

Why It Is Mathematically Perfect

Proving that Fisher-Yates produces a uniform distribution is straightforward. For a list of n items, there are n! possible orderings. The algorithm makes exactly n choices (one per step), and each choice is uniform over the remaining options. The total number of possible choice sequences is n × (n-1) × (n-2) × ... × 1 = n!. Each sequence maps to exactly one ordering. Therefore, each ordering appears with probability 1/n! — exactly equal.

Compare this to the naive shuffle, where the number of choice sequences is n^n (you always choose from all n positions), but there are only n! orderings. Since n^n is greater than n! for any n > 2, some orderings must be more likely than others — the choices cannot map cleanly to orderings.

For practical purposes, Fisher-Yates runs in O(n) time — it processes each item exactly once. It also requires no additional memory beyond the original list. It is as efficient as it is fair.

The Role of the Random Number Generator

Fisher-Yates is only as good as the random number generator (RNG) it uses. A truly uniform shuffle requires a truly uniform source of randomness at each step. Most programming languages provide a "pseudo-random" number generator (PRNG) — a deterministic algorithm that produces sequences of numbers that appear random but are fully determined by an initial "seed" value.

For most everyday applications — shuffling playlists, picking names, randomizing lists — a PRNG is perfectly adequate. The sequences are random enough for practical purposes, and without knowing the seed, they are effectively unpredictable.

RandomLists.app uses JavaScript's Math.random() function, which modern browsers implement using a cryptographically seeded PRNG. For everyday decision-making and fair selection, this is more than sufficient. For applications requiring cryptographic security — generating encryption keys, running high-stakes lotteries — dedicated cryptographic RNGs are used instead.

Fisher-Yates in the Real World

The Fisher-Yates shuffle is so ubiquitous that it is easy to forget how fundamental it is. Every time Spotify shuffles your playlist, Fisher-Yates (or an equivalent) is running. Every time a research study randomizes participants into treatment and control groups, Fisher-Yates ensures the groups are truly comparable. Every time a game deals cards, assigns random teams, or generates a random level layout, Fisher-Yates is typically the underlying mechanism.

In education, tools that use Fisher-Yates to randomize student selection ensure that participation is genuinely fair — not just approximately fair, but mathematically provably fair. In business, random assignment of A/B test participants using Fisher-Yates ensures that results are statistically valid.

The next time you use a randomization tool and wonder whether the result is truly fair, look for whether the implementation uses Fisher-Yates or an equivalent uniform shuffle. If it does, you can trust the math. If it uses a naive shuffle — or worse, a human "random" selection — you should be more skeptical.

At RandomLists.app, every shuffle and pick uses the Fisher-Yates algorithm. When you click "Shuffle List" or "Pick a Winner," you are getting a mathematically uniform result — the same quality of randomness used in professional lottery systems, just applied to your everyday decisions.

AA

Adnane Amzil

Adnane Amzil is a developer and the creator of RandomLists.app. He writes about decision science, algorithms, and building tools that help people choose faster.