Random List Shuffler
Paste a list, get it back in a random order. Every possible order is equally likely — which is not true of the one-line trick most pages use.
How to use it
- Paste your list with one item per line.
- Press Shuffle. Press it again for a different order.
- Keep only the first few turns a shuffle into a draw: shuffle thirty names and keep three and you have picked three at random, fairly.
The one-line shuffle that does not work
Search for how to shuffle a list and the first answer you will find is one line long:
list.sort(function () { return Math.random() - 0.5; })
It looks random, it runs, and it is wrong. A sort works by asking “does A come before B?” and it assumes the answer is consistent: if A beats B and B beats C, then A beats C. A random answer breaks that promise, so the sort is working from contradictory information and the order it lands on depends on the internal details of the sorting algorithm rather than on chance.
The result is measurably uneven — some orders come up far more often than others, and items often drift only a little from where they started. Exactly how it is uneven changes from browser to browser, which is worse than a bias you can at least predict. Run it a few thousand times and count: the lopsidedness is obvious.
What this page does instead
Fisher-Yates, which is the correct answer and is barely longer. Walk the list from the end; for each position, pick one of the items not yet placed and swap it in. Each item has exactly one chance to land in each spot, so all possible orders are equally likely.
The random numbers come from crypto.getRandomValues,
with the leftover values thrown away so that no position is even
fractionally favoured. Fair shuffle, fair numbers.
A shuffle of a long list is a big number
Ten items can be arranged 3,628,800 ways. Twenty items can be arranged in more ways than there are grains of sand on Earth. You will never see the same shuffle twice on any list worth shuffling, and there is no need to press the button repeatedly hoping for something “more random” — the first one already was.
Frequently asked questions
Why not just use the sort trick?
Because a sort assumes its comparisons are consistent and a random comparison is not, so the order you get depends on the sorting algorithm rather than on chance. It is measurably uneven, and differently uneven in different browsers. Fisher-Yates is barely longer and is actually correct.
How do I pick winners instead of reordering?
Shuffle the whole list and keep the first few, using the box above. That is a genuinely fair draw - every entry had the same chance of landing in the top spots.
Does it keep my blank lines?
Not by default, because a blank line is almost never an item you meant to include. Untick 'ignore blank lines' if the gaps matter to you and they will be shuffled along with everything else.
What counts as a duplicate?
An identical line once the spaces at each end are removed. 'Anil' and 'anil ' are treated as different, because names and codes often differ meaningfully in capitals and the page should not guess otherwise.
Is there a limit on list length?
A hundred thousand lines, which is far past anything a person reads. Very long lists shuffle instantly, because the work grows in step with the list rather than faster.
Is my text sent anywhere?
No. Everything happens in JavaScript inside your own browser. Nothing is uploaded and nothing is saved - close the tab and it is gone.