Deterministic seeds for procedural worlds
procedural-generationhashingdeterminismdartsave-games
If a procedurally generated world must be the same every time it loads (for save games, persisted broken objects, or sharing), every random choice must come from a seed that is stable across runs, platforms and edits. Two separate traps were hit in Spacebar.
Trap 1: language hash functions are randomized per run
Dart's Object.hash (like many runtime hash functions, e.g. Python's string hash) is seeded randomly per
process. Using it to seed zone generation meant structures, AI and pickups reshuffled on every
launch, which silently broke persistence of "broken structure" ids.
Fix: a dedicated stableSeed() with a fixed algorithm (e.g. FNV-1a or a simple integer mix), plus unit
tests that pin exact output values. The test should warn that changing the algorithm reshuffles every
existing save. For a Dart app that compiles to both VM and JS, prove parity by running the pinned tests on
both (integer overflow semantics differ on the web).
Trap 2: sequential RNG streams make edits non-local
If filler is drawn from one seeded RNG stream in iteration order, inserting a single road changes how many random numbers come before every later tile, and the whole map changes. Hash the position (and a purpose salt) for each decision instead, so an edit only changes what is near it.
Practical rules
- Anything with persistent identity (landmarks, quest objects) is authored data, not generated filler.
- When the world-gen algorithm must change, bundle all pending seed changes into one deliberate, one-time reshuffle and migrate or invalidate saves.
- Seed using all relevant coordinates; Spacebar's terrain seeded with only one axis term is a known shortcut that produces correlated output.
See also
Linked from
- A registry-driven choose-your-own-adventure engine (Archipelago: Voyages)
- Flutter and Dart gotchas (collections, widgets, theming)
- Generating Trackmania 2020 maps with GBX.NET
- Parallel reductions and associativity (std::transform_reduce as the case study)
- Procedural planet generation with causes (A Planet With a Past)
- Road-graph map pipeline (author roads, generate the rest)
- Static trivia and quiz games (daily sets, question banks, fact checking)
- Wave function collapse for island terrain (and why it never contradicts)