Shuffle Words and Lines

Three kinds of shuffle: reorder the words in a sentence, reorder a list of lines, or scramble the letters inside each word for a puzzle.

Words, lines and letters

Shuffling words reorders the tokens in a sentence and is the basis of a sentence-reconstruction exercise: hand someone the shuffled version and ask them to rebuild it. Shuffling lines randomises a stacked list, which is how you draw a random order for a rota, a playlist or a presentation running order without picking favourites. Shuffling the letters inside each word leaves the words in place but scrambles their spelling, producing the classic word-jumble puzzle where the sentence structure is still visible but each word has to be decoded.

A genuinely uniform shuffle

The shuffle uses the Fisher-Yates algorithm, which produces every possible ordering with equal probability. The common alternative, sorting with a random comparator, looks like it should work and does not: it biases certain positions, and with some sort implementations it can return the original order far more often than chance would suggest. That bias does not matter for a party game but it does for anything where the fairness of the draw is the point. Letter shuffling deliberately skips one-character words and leaves punctuation attached, so the shape of the sentence survives.

Frequently asked questions

Is the shuffle actually random?

It uses Fisher-Yates, which gives every ordering an equal chance. That is not true of the common trick of sorting with a random comparator, which is measurably biased.

Why do some short words come back unchanged?

Letter shuffling skips words under two characters, and any short word can shuffle back into its original order by chance, that is a property of a genuine shuffle, not a bug.

Can I get the original text back?

No. A shuffle discards the original order, so keep a copy of your input if you need it. Refreshing produces a different arrangement, not the original.