📚 Encyclopedia

Games & Graphics · updated 2026-10-13

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

See also

Linked from

Sources: spacebar memory (project_improvement_cycles, project_map_pipeline)