Shuffle lines into a random order
Use this tool to shuffle lines: it takes a list with one item per line and returns the same lines in a random order. Nothing is added, removed or edited apart from optional blank lines. Each run produces a fresh order.
Example
Before After (one possible result)
Alice Dave
Bob Carol
Carol Frank
Dave Alice
Eve Eve
Frank Bob
Six names can be arranged in 6! = 720 ways, and ten lines in 3,628,800 ways. A line can land in its original spot by chance, as Eve did above; that is normal for a fair shuffle.
How the shuffle works
The tool uses the Fisher–Yates shuffle. It walks from the last line to the first and swaps each one with a randomly chosen line at or before it. Given a good random source, every possible order is equally likely. Simpler approaches, such as sorting with a random comparison, are known to favor some orders.
The random numbers come from your browser's built-in Math.random(). That is statistically fine for classroom draws, team orders and test data. It is not a cryptographically secure generator, though, so do not rely on it for prize draws with money involved or anything security-related.
Blank lines and duplicates
With empty-line removal on, blank lines and lines that contain only spaces are dropped before shuffling, so they cannot end up scattered through your list. Lines themselves are not trimmed, and duplicate lines are kept. A name listed twice is twice as likely to come first. Clean the list with remove duplicate lines if each entry should appear once.
Shuffling lines elsewhere
If you need to shuffle as part of a script or spreadsheet, these are the usual options:
- Linux:
shuf names.txtfrom GNU coreutils prints the lines in random order. On macOS it is available asgshufafter installing coreutils. - Beware of
sort -R. GNU sort's random mode orders lines by a random hash, so identical lines always end up next to each other. That is not a true shuffle when your list contains duplicates. - Excel or Google Sheets: add a helper column with
=RAND(), then sort by it. The values recalculate on every edit, so copy the shuffled list somewhere else before you change anything. - Python:
random.shuffle(lines)uses Fisher–Yates, like this page; usesecrets.SystemRandom().shuffle(lines)when the order must be unpredictable.
Practical uses
- Quiz and exam questions – produce a different question order for each group.
- Presentation or turn order – shuffle the names and read from top to bottom.
- Teams – shuffle a roster, then split it into consecutive blocks of equal size.
- Test data – check that code does not depend on input order.
- Playlists and reading lists – break an alphabetical or chronological order.
Related tools
To pick one or a few winners rather than order the whole list, the random name picker is quicker. To restore a predictable order afterwards, sort text lines alphabetically. To jumble letters instead of lines, try the letter randomizer.
Privacy
The processing runs entirely in your browser. The text you enter is not uploaded to a server.