FormatterHQ

Shuffle Lines

Put the lines of any list into a random order, with every order equally likely. Useful for draws, quiz questions, playlists and test data.

Input TEXT
Output TEXT
Ready.

How to use the Shuffle Lines

  1. Paste your list with one item per line.
  2. Choose whether empty lines should be removed first.
  3. Shuffle, and shuffle again for a new order.
  4. Copy the randomized list.

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.txt from GNU coreutils prints the lines in random order. On macOS it is available as gshuf after 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; use secrets.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.

Frequently asked questions

Is the shuffle truly random?
It uses the Fisher–Yates algorithm, which makes every order equally likely given the random source. The source is the browser's Math.random(), which is fine for everyday use but not cryptographically secure.
Why did some lines stay in the same position?
In a fair shuffle any line can end up where it started. With six lines, there is about a 63% chance that at least one line stays put, so this is expected.
Does shuffling remove duplicate lines?
No. Every line is kept, including duplicates. Remove duplicates first if each item should appear only once.
How do I split a list into random teams?
Shuffle the list, then take consecutive blocks: for example, lines 1–5 are team A and lines 6–10 are team B. Because the order is random, the teams are random too.

Last updated September 26, 2026

Related tools