How AnyTool Builds a Unique-Solution Sudoku
Generation is a two-stage pipeline that runs entirely in the browser. First, an empty 9×9 grid is filled by recursive backtracking: at each cell the candidate digits 1–9 are tried in an order shuffled with the Web Crypto API (crypto.getRandomValues via rejection sampling, never Math.random), producing a uniformly-random complete and valid solution where every row, column and 3×3 box holds 1–9 once. Second, cells are dug out in a crypto-shuffled order, preferring 180°-rotationally symmetric pairs for a clean printable look. Each candidate removal is accepted only if a counting solver — a backtracking search with a minimum-remaining-values heuristic that stops the moment it finds a second answer — confirms the puzzle still has exactly one solution; otherwise the cell (and its mirror) are restored. Digging continues until the difficulty’s target clue count is reached. Because every removal is uniqueness-checked, the returned puzzle is guaranteed solvable by logic alone, with no guessing.
- Stage 1: randomized backtracking fills a full valid grid (Web Crypto shuffle, not Math.random)
- Stage 2: cells removed in symmetric pairs, each kept only if the solution stays unique
- Uniqueness checked by a counting solver (MRV heuristic) that stops at the 2nd solution
- Guaranteed exactly one solution — finishable by logic without guessing
- All generation, solving and printing run client-side; nothing is uploaded
