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.
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.