What people shuffle
- The running order for talks, interviews or a recital, so nobody can say it was arranged.
- Quiz questions in a different order for each class, with a repeat key per class so the answer sheet can be rebuilt.
- Answer options in a survey, to dilute the order effect that favours whatever is listed first.
- A class list dealt into random groups.
Every order equally likely
The shuffle is Fisher–Yates: walk from the last position to the first, and at each one swap in an item chosen uniformly from that position or any before it. Every one of the n! possible orders is then equally likely: 3,628,800 for ten lines, about 8.07 × 10^67 for a deck of 52 cards.
The positions are drawn with the browser’s Web Crypto generator, crypto.getRandomValues. Taking a 32-bit random number modulo the range would favour some results slightly, so values above the largest multiple of the range are thrown away and drawn again. For a choice among ten, the top 6 of the 4,294,967,296 possible values are rejected, leaving exactly 429,496,729 values for each of 0 to 9.
Why the popular one-liner is biased
A common shortcut sorts the list with a comparison that returns a random answer, sort(() => Math.random() − 0.5). Sorting algorithms assume comparisons are consistent, so the result is skewed. Shuffling A, B, C that way 600,000 times in Node.js gave the original order ABC 224,586 times, about 37%, and CAB only 37,409 times, about 6%. A fair shuffle gives each of the six orders about 100,000, or 16.7%. Other JavaScript engines skew differently, but they all skew.
How a repeatable shuffle works
Type anything into the repeat field and it is hashed to a 32-bit starting value (FNV-1a), which drives a small pseudo-random generator (mulberry32) that picks the Fisher–Yates positions. The same list with the same key gives the same order on any device, any day.
Because the starting value has 32 bits, a keyed shuffle can produce at most 2^32, about 4.3 billion, different orders. Thirteen lines already have 6,227,020,800 possible orders, so with a key some of them can never appear. Use a key when you need to rebuild an order, and leave it empty for a draw.
Good to know about groups
Groups are dealt from the shuffled list one name at a time, like cards. Seven people numbered 1 to 7, shuffled with the key “x”, come out as 2, 3, 7, 6, 5, 1, 4; in three groups that gives group 1: 2, 6, 4, group 2: 3, 5 and group 3: 7, 1. Dealing keeps group sizes within one of each other.
- Asking for more groups than there are names gives one group per name: three names in five groups is three groups of one.
- A name on two lines counts as two people. Run the duplicate-line tool first if the list may contain repeats.
- If each group needs a leader, agree beforehand that, say, the first name in each group takes the role, so the draw settles it.