Logo

MonoCalc

/

Line Shuffler

Text
Enter some text to shuffle — one item per line.
0 lines0 chars0 BNo line breaksProcessed in your browser

Quick presets

Action

Reverse, sort and original are deterministic companions — handy for comparing a shuffle against a known baseline.

Shuffle mode

Pin seed

Any whole number between -2,147,483,648 and 2,147,483,647.
Seed 01 possible orderings0 movable items

How lines are read and written

How the text is split into lines.
A regular expression, for example \s*,\s* to split on commas and any spaces.
How the shuffled lines are joined back together.
Escape sequences such as \n and \t are interpreted.

Cleanup

Trim whitespace

Remove blank lines

Remove duplicates

Ignore case

Number output

Locked lines

Keep header row

Keep footer row

Lock every Nth line

Every Nth line stays put.
Lines per block in the block modes.
Lines kept after shuffling, in sample mode.
How blocks are detected.
Leave empty to use a blank line.
Extra rounds do not improve uniformity.
Decimal places in the statistics panel.
0 lines · 0 characters · 0 B

About This Tool

Line Shuffler – Randomize the Order of Any List

Sooner or later every list needs to be put in no particular order. Who presents first, which name is drawn, which rows go into the training split, which question a learner sees third — all of them are the same request: take these lines and rearrange them so that no ordering is favoured over any other. A line shuffler does exactly that. Paste a block of text, and every line comes back in a fresh random position, with the whole operation running in your browser so a list of client names or unreleased data never leaves your machine.

Why the shuffle algorithm actually matters

The best-known way to shuffle an array in JavaScript is also wrong. Writing array.sort(() => Math.random() - 0.5) looks clever and produces something that superficially resembles a shuffle, but sorting algorithms assume the comparator is consistent — that if a comes before b and b before c, then a comes before c. A random comparator breaks that promise, and the result is a measurably skewed distribution whose exact bias depends on which sort the engine happens to use. Items frequently stay near where they started.

This tool uses the Fisher–Yates shuffle, in the in-place form popularised by Knuth and Durstenfeld. It walks the list once from the end, and at each index i swaps that item with one chosen uniformly from positions 0 through i. The proof that it is unbiased is short: each of the n! orderings corresponds to exactly one sequence of swap choices, and every such sequence is equally likely. It also runs in linear time, so a hundred-thousand-line file shuffles as fast as it can be read.

Seeds, and why a random draw should be reproducible

Randomness and accountability sound like opposites, but a seeded shufflegives you both. Pin a seed — any whole number — and the same input always produces the same ordering, so a draw can be written down, re-run, and checked by somebody else. That is what makes a raffle defensible, a train/test split reproducible, and a bug report reproducible when it only appears for one particular ordering of the data. Leave the seed unpinned and a new one is drawn from the browser's cryptographic random source for every reroll, then reported back to you, so even a spur-of-the-moment shuffle can be reproduced afterwards.

Fixed points are normal, not a bug
Around one line in any shuffled list typically lands back on the position it started from. This is not a sign the shuffle failed — the expected number of such fixed points is almost exactly 1 regardless of whether the list has ten entries or ten thousand, a classic result related to the derangement problem. The statistics panel counts them so you can see this for yourself.

Shuffling structure, not just lines

Real text is rarely a flat list. Shuffle within blocks keeps block boundaries fixed and only mixes lines inside each block — the right granularity for randomizing four answer options per quiz question. Shuffle blocks does the opposite: whole paragraphs or records are reordered while the lines inside each keep their sequence, with boundaries taken either from a fixed block size or from a blank line or custom marker. Locked lines pin a header row, a footer, or every Nth line in place, which is how a CSV keeps its column names on line one while the data rows below it are randomized.

Random sampling without replacement

Shuffling the whole list and keeping the first N lines is the simplest correct way to draw a random sample without replacement. Because the underlying permutation is uniform, every subset of size N is equally likely and no line can be drawn twice — which is why picking five winners from five hundred entries, or a hundred rows from a log file, is a shuffle-and-truncate rather than five separate random picks.

Cleanup, delimiters and reading the results

Before anything is shuffled, the text is split on the delimiter you choose — newline, comma, semicolon, tab, pipe, or a custom regular expression — and optionally trimmed, stripped of blank lines, and de-duplicated with or without case sensitivity. Duplicates deserve attention: two identical lines make a perfectly fair shuffle look less random, because swapping them changes nothing visible. The statistics panel reports the number of possible orderings (n!, which passes the number of atoms in the observable universe at around 60 items), the average and maximum distance lines travelled, and the count of fixed points, while the mapping table and CSV export record exactly where every original line ended up.

Frequently Asked Questions

Is the Line Shuffler free?

Yes, Line Shuffler is totally free :)

Can I use the Line Shuffler offline?

Yes, you can install the webapp as PWA.

Is it safe to use Line Shuffler?

Yes, any data related to Line Shuffler only stored in your browser (if storage required). You can simply clear browser cache to clear all the stored data. We do not store any data on server.

How does the Line Shuffler work?

Your text is split into lines, cleaned according to the options you picked, and then reordered with the Fisher-Yates (Knuth) shuffle. That algorithm walks the list once from the end, swapping each item with a randomly chosen item at or before it, which produces every one of the n! possible orderings with exactly equal probability. Everything runs in your browser — the text is never uploaded.

Why not just use sort with a random comparator?

The popular one-liner array.sort(() => Math.random() - 0.5) is not a shuffle. Sorting algorithms assume the comparator is consistent, and an inconsistent one leaves the result skewed in a way that depends on the engine's sort implementation — items near their starting position tend to stay there. Fisher-Yates makes no such assumption and is provably uniform, so this tool uses it instead.

What does the random seed do?

A seed makes the shuffle reproducible: the same text plus the same seed always yields the same ordering, so a draw can be documented, shared, and verified by someone else. Leave the seed unpinned and a fresh one is drawn from the browser's cryptographic random source for every run and reported back to you, so even an unplanned shuffle can be reproduced afterwards from the seed shown.

Can I keep a header row or other lines in place?

Yes. Lock the header, lock the footer, or lock every Nth line, and those positions are held while everything else is shuffled around them — which is what a CSV with a column-name row needs. The block modes give you the other two granularities: shuffle only within fixed blocks, or reorder whole blocks while the lines inside each block keep their original sequence.

What are fixed points and why is the count usually about one?

A fixed point is a line that landed back on the position it started from. Each line has a 1-in-n chance of that happening and there are n lines, so the expected number of fixed points is almost exactly 1 no matter how long the list is. Seeing one or two lines apparently unmoved is normal and is not a sign that the shuffle failed.

How random is the result really?

The permutation is uniform, but the number of distinct shuffles you can reach is bounded by the seed, which is a 32-bit integer — about 4.3 billion starting states. That covers every possible ordering for lists up to 12 lines and remains statistically excellent beyond that, though it is not a substitute for a certified draw system in a regulated lottery.