ELI5: Explain Like I'm 5

Fisher–Yates shuffle

The fisher-yates shuffle is a way to randomly shuffle a set of things. Let's say you have a deck of cards and you want to shuffle them so that they're all mixed up. Here's how you can do it using the fisher-yates shuffle:

1. First, you write down the numbers 1 to 52 on separate pieces of paper. Each number represents a card in the deck.

2. Then you put all the pieces of paper into a hat or a bowl or something.

3. Now you're going to randomly pick one piece of paper at a time and write down the number that's on it. But there's a catch: once you pick a number, you don't put the paper back in the hat. This means that each number can only be picked once.

4. So you start by picking a number at random from the hat. Let's say you pick the number 35. You write down "35" on a separate piece of paper. This is going to be the first card in the shuffled deck.

5. Then you pick another number from the hat. Let's say you pick the number 12. You write down "12" on a separate piece of paper. This is the second card in the shuffled deck.

6. You keep doing this until you've picked all 52 numbers. Each number represents a card in the shuffled deck, and because you've picked them all randomly without repeating any, you've effectively shuffled the deck!

7. Now you just need to put the cards in order according to the numbers you wrote down. So the first card in the shuffled deck is the card that corresponds to the number you picked first (in our example, that was number 35), the second card is the one that corresponds to the second number you picked (number 12), and so on.

That's it! This is a simple example of the fisher-yates shuffle, but the same principle can be applied to shuffle any set of things, not just cards. And the great thing about the fisher-yates shuffle is that it ensures that each item in the set has an equal chance of being picked first, second, third, and so on.