Fair teams, and what an unbiased shuffle has to do
Splitting a list into teams sounds like one step and is really two: put the names in a random order, then deal them out. The dealing part is easy to get right. The ordering part is where almost every hand-written attempt goes wrong, and the failure is quiet — the output looks jumbled, so nobody checks.
The dealing part
Once the names are in a random order, deal them round-robin: first name to team 1, second to team 2, and so on, wrapping around. With 7 names and 2 teams that gives 4 and 3. With 10 names and 3 teams, 4 and 3 and 3. Sizes always end up within one of each other, whatever the numbers, because each team gets one name per full pass and the leftovers are spread one apiece. No balancing logic is needed — the dealing order does it.
All the fairness therefore rests on the shuffle that came first. If the shuffle favours some orderings, the teams inherit that favouritism.
The shuffle almost everyone writes first
Here is the natural version: walk through the list position by position, and at each position pick a random slot anywhere in the whole list and swap the two. It touches every element, it uses fresh randomness at every step, and the result looks thoroughly mixed. It is also biased, and you can prove it by hand.
Take three names, A, B and C. Each of the three steps picks one of three slots, so there are 3 × 3 × 3 = 27 equally likely paths through the algorithm. There are only 3 × 2 × 1 = 6 possible orderings. For every ordering to be equally likely, 27 would have to divide evenly by 6 — and it does not: 27 ÷ 6 = 4.5. Some orderings must get more paths than others. There is no way to arrange it otherwise, and this argument holds for every list size, because a count of the form n to the power n is never divisible by n factorial once n is 3 or more.
Working all 27 paths through gives the split exactly. Three orderings get 5 paths each and three get 4 paths each:
- ACB, BAC, BCA — 5 paths out of 27 each, about 18.52%
- ABC, CAB, CBA — 4 paths out of 27 each, about 14.81%
The counts add to 5 + 5 + 5 + 4 + 4 + 4 = 27, so nothing was missed. Those favoured orderings come up 25% more often than the others — 5 ÷ 4 = 1.25. On four names it is worse: 256 paths across 24 orderings, and the luckiest ordering gets 15 of them against the unluckiest ordering's 8, close to double.
That is not a rounding artefact you can wave away. It is a systematic tilt that no amount of re-running removes, because every run has it.
What an unbiased shuffle has to do
The fix is small and specific. Walk the list from the last position backwards, and at each position pick a random slot from the part of the list you have not already finalised — that is, from the start up to and including the current position — and swap. Never reach into the part you have already settled.
The reason it works is a count again. The first step chooses among n slots, the next among n − 1, then n − 2, and so on. Multiply those together and you get exactly n factorial paths for exactly n factorial orderings — one path each, so every ordering is equally likely, with nothing left over to distribute unevenly. On three names that is 3 × 2 = 6 paths for 6 orderings, against the naive version's 27 for 6.
This is the Fisher–Yates shuffle, and it is what this tool runs. The one detail that separates it from the biased version is the shrinking range: pick from the unfinished part, including the current position, never from the whole list.
One caveat, stated for completeness
The random slot is chosen by taking a generator value modulo the range size, which makes a few slots very slightly more likely than the rest when the range does not divide the generator's span evenly. The size of that effect is roughly the range divided by 2^64 — for a list of 20 names, under 2 parts in 10^18. It is far below anything a team night could notice, and it is the only bias left once the shuffle itself is correct.
The tool
The Random Team Picker shuffles your names with Fisher–Yates, deals them round-robin into the number of teams you ask for, and runs entirely on your device. It uses the same seeded generator as the rest of the site, which is right for a games night and wrong for anything where the outcome is worth money — for a draw people need to be able to check, use the site's Reproducible Fair Draw tool instead, where the seed is agreed in advance and published.