The Fisher–Yates Shuffle Explained in Plain English
Shuffling a list looks trivial: just mix it up. Yet many quick methods quietly favor some orders over others, which matters when the list decides who presents first, which task gets done next or which name wins a prize. The Fisher–Yates shuffle is the classic answer to this problem. Here is how it works, why it is fair, and how to use it on your own lists.
A Short History of the Algorithm
The method was published in 1938 by statisticians Ronald Fisher and Frank Yates as a pencil-and-paper procedure for randomizing experiments: write the numbers down, pick one at random, cross it out and repeat. In 1964 Richard Durstenfeld described a version suited to computers, and Donald Knuth later popularized it in The Art of Computer Programming. Today it is the standard shuffle in most programming languages.
How Fisher–Yates Works, Step by Step
The modern version walks through the list from the end to the start:
- Start with the last position in the list.
- Pick a random position from the first item up to and including the current one.
- Swap the two items.
- Move one step towards the start and repeat until you reach the first item.
Take the list A, B, C, D. For the last slot you choose randomly among all four items; say B, so B and D swap. For the third slot you choose among the remaining three, and so on. Each item gets exactly one fair chance at each position, and the shuffle needs only one pass through the list.
Why “Sort by Random” Is a Trap
A popular shortcut is to sort a list with a comparison that returns a random answer. It looks clever and often seems to work, but the result depends on the sorting algorithm and is usually biased: some items tend to stay near their starting position. Another common mistake is picking the swap position from the whole list at every step instead of the shrinking range. That produces more possible paths than there are orderings, so some orders appear more often than others.
Fisher–Yates avoids both problems. With a good random number source, every one of the possible orderings is equally likely. For four items that is 24 orders; for ten items it is 3,628,800.
Shuffling Your Own List With the List Randomizer
The tool above runs Fisher–Yates with random numbers from the Web Crypto API. To use it:
- Paste or type your items into Your list, one per line. Blank lines are ignored.
- Press Generate.
- Read the result: every item comes back with its new position, such as “Task C (#1)”, “Task A (#2)”.
- Copy the list, export it as CSV, JSON or TXT, or share a link that keeps your list in place.
Nothing is added, removed or duplicated, and the list never leaves your browser.
Practical Ways to Use a Fair Shuffle
- Presentation order for a class or a sprint demo.
- Chore rotation where nobody wants to be first on bins.
- Study revision: shuffle flashcard questions so you do not memorize the order.
- Playlists and reading lists when you cannot decide what comes next.
- Tournament seeding for casual games.
When you need groups rather than an order, split the shuffled list into teams instead.
Testing a Shuffle Yourself
You do not need to read code to check whether a shuffle is fair. Try this simple experiment with a three-item list such as A, B, C:
- Shuffle the list many times — thirty or more runs is a good start.
- Each time, note which item lands in first place.
- Count the results for each item.
With a fair shuffle, each item should land first roughly a third of the time. Small differences are normal, because randomness is lumpy over short runs; the counts even out as you add more runs. If one item keeps winning by a wide margin across hundreds of runs, the method is biased. You can also count the six possible full orders — ABC, ACB, BAC, BCA, CAB and CBA — which should all appear about equally often.
This is exactly the kind of test that exposes the “sort by random” shortcut, and it is a fun way to show students what fairness means in practice.
Pro tips
- Remove duplicates before shuffling if each person should appear only once.
- Save the export whenever the order has consequences, such as a prize draw.
- Shuffle once and stick with it; re-rolling until you like the result defeats the purpose.
- For very long lists, number the items first so you can check nothing was lost.
Frequently asked questions
Who invented the Fisher–Yates shuffle?
Ronald Fisher and Frank Yates described it in 1938. Richard Durstenfeld published the efficient computer version in 1964, which is why it is sometimes called the Knuth or Durstenfeld shuffle.
How many ways can a list be ordered?
A list of n distinct items has n factorial orderings: 6 for three items, 120 for five and over 3.6 million for ten.
Is shuffling a list the same as picking a random item?
Not quite. Picking gives you one item, while shuffling gives a complete order. The first item of a fair shuffle is, however, a fair random pick.