Dev.to WebDev πŸ›  Dev πŸ‘ 0 πŸ“– 4 min read

A daily Sudoku with no server: seeded RNG, uniqueness checks and a human-style difficulty grader

Our browser Sudoku game, Sudoku Sprout, has a Daily mode: everyone who opens it on the same date gets the same puzzle, there is a 7-day archive, and a streak counter. There is no backend involved. The puzzle is generated

Our browser Sudoku game, Sudoku Sprout, has a Daily mode: everyone who opens it on the same date gets the same puzzle, there is a 7-day archive, and a streak counter. There is no backend involved. The puzzle is generated on the player's device, in about 2 ms, from nothing but the date.

This post walks through the three pieces that make that work: a seeded random number generator, a uniqueness check, and a "human" logic grader that decides difficulty. All numbers below come from running the actual engine in Node.

1. The date is the seed

The date string becomes an integer (2026-11-29 β†’ 20261129), and that integer seeds a tiny PRNG:

export function mulberry(a) {
  return () => {
    a |= 0; a = a + 0x6D2B79F5 | 0;
    let t = Math.imul(a ^ a >>> 15, 1 | a);
    t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
    return ((t ^ t >>> 14) >>> 0) / 4294967296;
  };
}

const dayKey = Number(date.replaceAll('-', ''));
const g = generate('medium', mulberry(dayKey * 31 + 7));

Mulberry32 only uses 32-bit integer operations (Math.imul, shifts, >>> 0), so it produces the same sequence in every JavaScript engine. That matters: if the generator used Math.random() anywhere, or relied on floating-point behavior that differs between engines, two players would quietly get different "daily" puzzles. Running the generator twice for 2026-11-29 gives byte-identical grids.

One small trap: the date comes from the player's local calendar (the Daily grows at local midnight), but date arithmetic for the archive uses UTC, so a daylight-saving change can't skip or repeat a day:

// Use UTC for calendar arithmetic only, so a DST change cannot skip a date.
const day = +new Date(today + 'T00:00:00Z') / 86_400_000;
const archive = Array.from({length: 7}, (_, i) =>
  new Date((day - i) * 86_400_000).toISOString().slice(0, 10));

2. Dig holes, but keep exactly one answer

Generation is the classic "fill, then dig" approach:

  1. Fill a complete valid grid with backtracking, shuffling candidate digits with the seeded RNG.
  2. Visit the 40 symmetric cell pairs (plus the centre) in a random order, and try removing each pair.
  3. Keep the removal only if the puzzle still has exactly one solution.

The uniqueness check is a backtracking solver that stops as soon as it finds a second solution:

if (countSolutions(puzzle, 2) !== 1 || !logicSolve(puzzle, L.maxTech).solved) {
  puzzle[i] = a; puzzle[j] = b; // put the clues back
  continue;
}

Passing limit = 2 is the whole trick. We never need to know how many solutions a grid has, only whether there's more than one, so the search ends early on bad candidates. The solver also picks the empty cell with the fewest candidates first, which keeps it fast enough to call hundreds of times per puzzle.

3. Difficulty = the hardest technique a human needs

A unique puzzle can still be miserable if the only way forward is guessing. So every removal also has to pass logicSolve, which solves the grid the way a person would, cheapest technique first:

Level Techniques allowed
1 naked single
2 hidden single
3 locked candidates (pointing / claiming)
4 naked / hidden pairs
5 naked / hidden triples
6 X-wing

Each difficulty sets a ceiling (maxTech), a floor (minTech), and a minimum clue count:

export const LEVELS = {
  easy:   {maxTech: 1, minTech: 0, floor: 38},
  medium: {maxTech: 2, minTech: 2, floor: 30},
  hard:   {maxTech: 3, minTech: 3, floor: 0},
  expert: {maxTech: 6, minTech: 4, floor: 0},
};

The ceiling guarantees the puzzle never needs a guess beyond what that level promises. The floor stops a "Hard" puzzle from accidentally being solvable with singles only. If a finished grid misses the floor, the generator starts over with a fresh full grid (up to 200 attempts).

The same grader powers the hint button: it asks for the next naked or hidden single on the player's current grid, so a hint is always a move a person could have found, not "the answer is 7".

The numbers

I ran the generator for 60 seeds per level (30 for Expert) in Node:

Level Median clues Median attempts Median time Worst time
Easy 38 1 0.5 ms 15 ms
Medium (Daily) 30 1 1.8 ms 6 ms
Hard 28 7 29 ms 192 ms
Expert 28 11 45 ms 513 ms

Zero failures across all 210 runs. This is why the Daily uses Medium: it almost always succeeds on the first full grid, so it's effectively instant even on a slow phone. Hard and Expert need several restarts because the "must require at least technique N" floor rejects many grids, which is why the game shows a short "Growing your puzzle…" overlay while it works.

Streaks without a server

Completed dates are stored in localStorage. The streak function sorts unique day numbers and counts consecutive runs, with one rule: the current streak is still alive if the last solve was yesterday, because today's puzzle can extend it. Only puzzles solved on their own day count toward the streak; replaying an archive day gets a checkmark but doesn't patch a gap. The share button copies one line with the time and a link to that day's puzzle, and no personal data.

Takeaways

  • A deterministic PRNG plus the date gives you a "daily" feature with zero infrastructure.
  • Check uniqueness with a solver that stops at 2 solutions.
  • Grade by the techniques a human needs, and enforce both a ceiling and a floor.
  • Measure generation time per level before choosing which one becomes the Daily.

You can play today's puzzle here: Sudoku Sprout on JumpBud

πŸ“° Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.