Skip to content
Once Books

How a word search generator places words

On this page

The short answer

How our word search generator works: seeded random placement, crossing letters, decoy fill, the answer key, and the gaps we measured in 10,000 test grids.

A word search generator works in three passes. It places each word from the list in a straight line, in one of up to eight directions, at a spot where every cell is either empty or already holds the matching letter. It fills every remaining cell with a random decoy letter. Then it keeps the coordinates of each placed word, which become the answer key. Our engine does all three from one seed, in 0.13 to 0.18 ms for a 15 by 15 grid of 12 words on Node 22.

The longer answer covers the rules behind each pass, what happens when a word won't fit, and one thing the engine doesn't check that you should know about.

Which directions can a word go in?

A word runs in a straight line in one of eight compass directions, and the difficulty level decides which ones are allowed:

export function directionsForDifficulty(level: DifficultyLevel): Direction[] {
  return level === DIFFICULTY_LEVEL.EASY
    ? ['E', 'S', 'SE']
    : level === DIFFICULTY_LEVEL.MEDIUM
      ? ['E', 'S', 'N', 'W', 'SE', 'SW']
      : ['E', 'W', 'S', 'N', 'SE', 'NW', 'SW', 'NE'];
}

Easy keeps words readable forwards: left to right, top to bottom, and down the diagonal. Medium adds backwards and upwards words and a second diagonal. Hard allows all eight. Each direction is a row and column step (E is [0, 1], NW is [-1, -1]), so walking a word is one loop for every direction.

Left alone, random choice tends to cluster words in one orientation. So each puzzle shuffles its allowed directions once, and each word leans towards the next one in that shuffled list, falling back to the others only if its preferred direction won't fit. The free word search generator uses the Medium set, and it's the same function the studio calls, so Medium means the same thing in both.

How does the generator decide where a word goes?

The generator samples random start positions for a word and keeps the legal one that crosses the most letters already on the grid. Words are placed longest first, because long words are the hardest to fit once the grid fills up. For each direction, the engine tries a fixed number of random starts and scores each one:

const ex = grid[r]?.[c];
if (ex !== '' && ex !== word[i]) {
  ok = false;
  break;
}
if (ex === word[i]) overlaps++;

That snippet is the entire collision rule: a cell can be shared only when both words need the same letter there, and a start is thrown out if the word would run off the edge or hit a different letter. Among the legal starts, the most shared cells wins. Words interlock the way crossword answers do. On the default animal list (12 words, 15 by 15, Medium), puzzles averaged 6.49 shared cells over 2,000 seeds.

Sampling is capped. The budget of 500 attempts is split across the allowed directions with a floor of 40 each, which works out to 167 starts per direction on Easy (3 directions), 84 on Medium (6) and 63 on Hard (8).

One honest note from the source: the comment above this function says it "returns as soon as it finds any crossing". The loop doesn't. It runs every sampled start and keeps the one with the most overlaps. Everything in this post describes what the code does, since that's the version that runs.

Which words go into a puzzle?

Each puzzle picks its words with a seeded shuffle of the word bank. This fixed a real bug. The engine used to take the first N words unshuffled, so every puzzle built from the same bank had the same word list, and only the grid layout changed with the seed. A constant-difficulty book printed identical word lists on every page. The fix is a seeded Fisher-Yates shuffle before the slice, which keeps a puzzle reproducible from its seed and still gives each page its own set.

For whole books, a separate dealer hands out the bank so every word is used once before any word repeats, and no page repeats a word within itself.

Where do the filler letters come from?

Filler letters are random, but a share of them is copied from the letters of the placed words, so the hidden words blend in. The share scales with difficulty:

const camouflage =
  difficulty === DIFFICULTY_LEVEL.HARD ? 0.75 : difficulty === DIFFICULTY_LEVEL.EASY ? 0.15 : 0.45;

On Hard, 75% of fill letters come from the puzzle's own letters, so the fill echoes the letters of the word list. On Easy, only 15% do, and the rest are drawn from 19 common English letters (ETAOINSHRDLCUMWFGYP), so letters like Z, Q and X only turn up in the fill when they're copied from a word. Medium and Hard draw everything else from all 26 letters, rare ones included.

Does the generator stop rude words or extra copies appearing?

Rude words, yes, now in two stages. Extra copies of a listed word, not automatically, and the studio's reshuffle is still the way out.

Every word crosses a profanity gate before it can be placed. The gate has two lists because of the Scunthorpe problem: mild words are blocked only as whole words (so GRASS, SHELL and GRAPE survive), while a short list of strong terms is blocked even inside a longer word. A few innocent words that contain a blocked stem, like CONGENITAL, are allow-listed. The API repeats the check on every placed word and title before it stores a book's puzzles, and rejects the save if one slips through.

For a long time that gate only ever saw the word list. The filler did not cross it, and random filler spells things. On the default 12-word animal list, 10,000 seeds per level, this is what the finished grids used to carry:

LevelGrids with a blocked term, any directionReading left to right or top downA listed word appears twice
Easy6.65%1.82%2.03%
Medium6.17%1.74%2.25%
Hard6.75%1.85%3.81%

"Blocked term" here means one of the 37 strong terms on the substring list, spelt out in a straight line anywhere in the grid, usually by filler letters or a crossing. Most are four-letter strings a solver would have to be looking for, but a family puzzle book shouldn't contain them at all.

So the grid is now read after it's filled. The engine walks every line in all eight directions, and where a blocked term appears it re-rolls the filler letters that spell it, drawing each replacement from the same decoy distribution so the camouflage doesn't change. Placed words are never touched, so the puzzle stays solvable and every theme word survives. The rare run a re-roll can't break, two crossing theme words that land a slur between them, throws the whole placement away and lays it out again at a new seed. Over 24,000 grids, 14 needed that fresh seed, and every one was clean on the very next try. A grid with a slur no longer reaches the page.

The extra-copy case in the last column is still open, and it's a solving problem rather than a safety one. If LION appears twice, a solver can circle the wrong one, and the answer key marks only the copy we placed. Hard is worst because its filler reuses the puzzle's own letters most often. The scan doesn't look for this, so the studio's one-click reshuffle, which re-lays the set at a new seed, is the way out.

What happens when a word won't fit?

The word is dropped from that puzzle, and nothing retries automatically. Placement is greedy: a word that finds no legal start in any allowed direction goes into unplacedWords, and the puzzle is flagged unapproved:

isApproved: unplacedWords.length === 0,

The printed word list is built from the placed words only, so a solver is never asked to find a word that isn't there. In exchange, a word can disappear quietly. The free tool doesn't mention it, and the studio shows each puzzle's word count rather than a warning. A reshuffle in the studio re-lays the same word set, dropped words included, with a new seed.

How often it happens depends on how full the grid is. Over 1,000 seeds each, at Medium:

  • 20 words on 15 by 15 (the free tool's cap): no puzzle dropped a word.
  • 20 words on 12 by 12: 458 of 1,000 puzzles dropped at least one, 563 words in total.
  • 36 words on 15 by 15: all 1,000 puzzles dropped words, 7,762 in total, which is about 7.8 missing words on every page.

The free tool caps the list at 20 words and each word at 15 letters, the grid width, so no single word is too long to fit and its numbers stay clean.

How is the answer key drawn?

The answer key comes straight from the stored cells of each placed word, so it can't disagree with the grid. Alongside the letter grid, the generator keeps a second grid holding only the placed letters. An answer page can shade those letters, or draw the traditional loop around each word. Each loop is one rounded rectangle, as long as the word and just under a cell tall, rotated to the word's angle about its midpoint. One rotated shape keeps a diagonal loop as clean as a horizontal one, where drawing it cell by cell would leave a staircase.

One last check runs at save time: the API refuses two puzzles with byte-identical grids.

If you want to watch the placement rules work, paste your own list into the free word search generator and press Generate a few times with the same words: the layout changes with every seed, and the answer page follows it. For a full book with a packed answer section, the KDP word search maker runs the same engine, our word search answer key guide covers how that section is laid out, and how to make and sell word search books on KDP takes it from file to listing. The sudoku engine takes the opposite approach to the same trust problem, re-solving the board after every clue it removes so it keeps exactly one solution.

Try the tool

Free, in your browser, no sign-up. Make one, then build the whole book in the studio.

Common questions

How does a word search generator work?
It sorts the word list longest first, then places each word in a straight line in one of the allowed directions, at a sampled start position where every cell is empty or already holds the same letter. When every word is placed, the empty cells get random filler letters, and the placed positions become the answer key.
Can words overlap in a word search?
Yes, where they share a letter. Two words may cross on a cell only if both need the same letter there. Our generator prefers the position with the most crossings, and a 15 by 15 puzzle of 12 animal words averaged about 6.5 shared cells in our tests.
Why does a word search generator leave words out?
The grid ran out of room. Placement is greedy with no backtracking, so once a word finds no legal spot in its sampled positions, it's dropped from that puzzle and from the printed word list. More words or a smaller grid makes this more likely.
Can a word search accidentally contain a rude word?
It used to. Filler letters are random, and random letters spell things, so about 6 in 100 of our early test grids read a blocked term in some direction. The generator now scans the finished grid in all eight directions and re-rolls the filler that spells one, so a clean grid goes to print. A placed theme word is never touched, so COMPASS, which contains ASS, is left as the buyer chose it.

Related reading

Keep reading

← All guides