GenerateRandomSearch

Text Wrapping and Raggedness Generator

Wrapping text to a fixed width is what every editor does, and almost all of them do it greedily: fill each line as far as it goes, then start the next. That is fast and it is not always the tidiest result. This wraps your text that way, scores the raggedness of the right edge, and confirms the wrapped lines still contain your words in your order — a check worth making, since a wrap that silently loses a word looks perfectly fine.

What this generator does

Fills each line with as many words as fit, then starts a new one. It scores raggedness as the squared leftover space on every line but the last, and verifies that reading the lines back gives your original words in their original order.

How to use this tool

  1. Paste the text to wrap.
  2. Set the line width in characters.
  3. Run, and read the wrapped lines and the raggedness score.
  4. Change the width and compare scores to find a tidier setting.

Understanding the controls

Text
The paragraph to wrap. Existing line breaks are treated as spaces, so the text is re-wrapped from scratch.
Line width
Between 10 and 120 characters, counting the spaces between words. A word longer than the width goes on its own line and overhangs, since it cannot be broken.

Common use cases

  • Formatting text to a fixed width for a terminal, email or code comment
  • Comparing widths by how ragged the right edge ends up
  • Teaching greedy line breaking and why it is not optimal
  • Preparing plain-text output for a system with a column limit
  • Checking how a paragraph will look before pasting it somewhere narrow

How this generator works

Each word is added to the current line if it still fits within the width, and otherwise starts a new line — the greedy rule. Raggedness squares the leftover space on each line except the last before adding it up, which is why one very short line scores worse than several slightly short ones. Before display, no line may exceed the width unless it is a single unbreakable word, no word may have fitted on the line before it, and reading the lines back must give exactly your words in exactly your order.

Randomness and fairness

Nothing here is random. The same text at the same width always wraps identically.

For how randomness is produced across the whole site, see how Generate Random works.

Limitations and good to know

  • Greedy wrapping is not the least ragged possible; a paragraph-wide method can sometimes even the lines out by moving a word down.
  • Words are never hyphenated or broken, so a word longer than the width overhangs its line.
  • Width is counted in characters, which only matches visual width in a monospaced font.
  • Existing line breaks are discarded rather than preserved, so deliberate breaks in the input are lost.

Privacy and your data

Wrapping happens entirely in your browser. Your text is never transmitted, stored or included in analytics.