HTML5 game publishing

A Daily Puzzle Without a Server: Seeded Random, UTC and Streaks

Everyone gets the same puzzle from a seeded generator and a date. UTC versus local day, the ways seeds diverge, storing results, computing streaks and sharing without spoilers.

PlayKovo Team4 min read
Games currently available on PlayKovo. Open a title to see its current listing.

A daily puzzle is one of the cheapest ways to give a game a reason to come back: everyone gets the same puzzle today, a new one tomorrow, and results are comparable. People assume that needs a server. It does not. With a seeded random number generator and one decision about time zones, you can ship a daily puzzle in a static HTML5 game with no backend at all. This post covers the whole thing, including the mistakes that make two players get different "daily" boards.

Step one: a deterministic random generator

Math.random() cannot be seeded, so every player would get a different puzzle. You need a small generator that produces the same sequence from the same seed. A common choice is mulberry32:

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

It is fast, tiny and good enough for games. It is not suitable for anything security related, but a puzzle does not need that. The important property is that the same seed always produces the same numbers on every device.

Step two: turn the date into a seed

The seed should be a number derived from the date. The key decision is which date:

function dailySeed(date = new Date()) {
  const y = date.getUTCFullYear();
  const m = date.getUTCMonth() + 1;
  const d = date.getUTCDate();
  return y * 10000 + m * 100 + d;   // e.g. 20261116
}

Using UTC means everyone worldwide gets the same puzzle at the same moment. The cost is that "today's puzzle" changes at an odd hour for some players, such as late afternoon in parts of the Americas or the middle of the night elsewhere. Using the local date makes the puzzle change at local midnight, which feels natural, but players in different time zones then see different puzzles on the same day, which breaks sharing and comparing results.

Pick one deliberately and tell the player. "New puzzle every day at 00:00 UTC" is honest and simple. If you want a local-midnight feel, accept that scores are not comparable across regions.

Step three: generate the puzzle from the seed

Create the generator at the start of the puzzle and use it for everything random in that puzzle:

const rng = mulberry32(dailySeed());
const puzzle = generatePuzzle(rng);

The rule is strict: once the puzzle is generated, no other code may call rng in a different order. If the order of calls differs between devices, the puzzles diverge. Common ways this goes wrong:

  • Looping over a Set or object whose iteration order differs between engines. Arrays are safe; sort anything else before use.
  • Skipping calls conditionally, for example only drawing a random number for devices with a certain screen size.
  • Using floating point results that differ slightly. Round values before you use them to make decisions.
  • Letting the generator depend on a changing word list. If you reorder or edit the list, every past and future seed changes. Version it.

For a puzzle that has to be solvable, generate it with a method that guarantees solvability and check it with a solver, as described in procedural puzzle levels and difficulty.

Step four: remember what the player did

Store the player's result keyed by the date seed. A tiny structure is enough:

const KEY = 'daily-v1';
function loadDaily() {
  try { return JSON.parse(localStorage.getItem(KEY)) || {}; }
  catch { return {}; }
}
function saveResult(seed, result) {
  const data = loadDaily();
  data[seed] = result;
  try { localStorage.setItem(KEY, JSON.stringify(data)); } catch {}
}

Wrap storage in try/catch, since it can be unavailable in private windows or embedded contexts. Use a version in the key so you can change the format later, as explained in save data versioning and migrations. If you want results to survive across devices, look at cloud save with a local fallback.

Streaks without a server

A streak is "consecutive days played". Compute it from the stored results, not from a counter:

function streak(data, today) {
  let n = 0, seed = today;
  while (data[seed]) { n++; seed = previousDay(seed); }
  return n;
}

Counting back from the stored records is more robust than incrementing a number, because it self-corrects if data is edited or lost in part. Decide whether today counts if the player has not played yet, and show the streak accordingly, so it does not appear to reset at midnight before they have had a chance.

Sharing the result

The best daily games let players share a result without revealing the answer. Build a short text from the outcome, such as a row of emoji for each attempt, and offer a copy button using navigator.clipboard.writeText, with a fallback of selecting the text for manual copy. Do not include a link to anything you do not control, and do not include personal data.

Things to decide before you launch

  1. UTC or local date for the day change.
  2. What happens when the player's clock is wrong. They can change it to replay or skip, so decide whether you care. For a casual game, you probably do not.
  3. What happens after the last pre-planned puzzle. Seeds are infinite, so this is not a limit, but a hand-authored list is.
  4. Whether past puzzles are replayable. An archive built from the same function is free, so it is a nice extra.

A daily puzzle also fits well with a good first impression. See the first 30 seconds of a browser game before you decide what the player sees on day one.

We use optional cookies for site analytics and site advertising. You can change your choice later. Privacy policy.