Procedural generation
A new galaxy every run
Remy wants every run of Hyper Shards to look different: new star fields, new nebula clouds, new wave orders. Drawing a hundred backgrounds by hand would take months.
Procedural generation means making content with rules plus randomness, often while the game runs. Levels, loot, maps and star fields can all be generated. Rogue (1980) built a new dungeon for every game, and today's roguelikes are named after it.
Random, but repeatable
Computers follow instructions exactly, so they cannot really roll dice. Instead they use a pseudo-random number generator (PRNG): a formula that turns one number into the next, so the results look random.
The first number is the seed. The same seed always gives the same list of numbers, so it always builds the same level.
JavaScript's Math.random() picks its own seed, and you cannot choose or reset it. So games that need repeatable levels use their own seeded generator, like the one on the next card.
Read the code
1// a tiny seeded random number generator2let seed = 12345;3function random() { // a number from 0 up to 14 seed = (seed * 1664525 + 1013904223) % 4294967296;5 return seed / 4294967296;6}7// each star: x = random() * 360, y = random() * 640
Kai draws 400 stars with this code, then reloads the page. What does the star field look like?
- Exactly the same, because the seed starts at 12345 again
- Completely different every time
- Empty, because the numbers run out
Show the answer
Exactly the same, because the seed starts at 12345 again
Each call turns the last number into the next with the same formula, so seed 12345 always gives the same list. These constants come from the classic book Numerical Recipes. To get a new sky, start from a different seed, like today's date.
What seeds are good for
- Daily challengesEveryone gets the same seed for one day, so all players face the same run. Slay the Spire's Daily Climb works this way.
- Sharing worldsMinecraft players swap seeds: type one in and you get the same world, as long as it is the same version of the game.
- Bug reports"Crashes on seed 4417, wave 3" lets Kai replay exactly the same run and watch the bug happen.
- Checking scoresReplaying a run with its seed and inputs shows whether a high score is real. The Stopping cheaters lesson in Stage 4 explains how.
Noise: randomness with shape
Pick every tile of a Garden Defense map with plain random numbers and you get speckles, like TV static: grass, mud, grass, mud. Nature is not like that. Mud comes in patches.
Noise is smooth randomness: points close together get similar values, so you get hills, patches and clouds. Ken Perlin created Perlin noise after working on the film Tron (1982), to make computer pictures look less machine-made, and later won an Academy Award for it. In 2001 he followed it with simplex noise, which needs less work.
Layering big and small noise gives wide hills and fine detail.
Quick check
Remy wants Garden Defense maps with natural patches of mud and grass, not a speckled mess. What should the generator use?
- Noise, so nearby tiles get similar values
- A new Math.random() roll for every tile
- One hand-drawn map, used every time
Show the answer
Noise, so nearby tiles get similar values
Noise is smooth randomness: neighbouring tiles get similar values, so mud and grass form patches. Separate random rolls make static, and one hand-drawn map is not generated at all.
Rules keep it playable
Randomness has no idea what fun is. It will happily wall Sprig in with hedges. So generators come with constraints, rules every result must pass:
- A path must exist from the pest gate to Sprig.
- At least 6 plant spots must sit next to that path.
- No two power-ups on the same tile.
A common method is generate and test: build a map, check every rule, and if one fails, throw the map away and try the next seed. To check that a path exists, run the breadth-first search from the Enemy brains lesson.
Player message
Seed 4417: the snails are stuck behind a hedge and can't reach Sprig. The wave never ends, so I can't finish!
What should Kai add to the map generator?
- A check that a path from the gate to Sprig exists, trying the next seed if it fails
- More hedges, so maps look more interesting
- A message telling players to restart if a wave seems stuck
- A rule that removes every hedge from every map
Show the answer
A check that a path from the gate to Sprig exists, trying the next seed if it fails
A constraint catches the broken map before any player sees it. More hedges make it worse, a restart message hides the bug, and removing every hedge throws away what makes maps interesting.
Hand-made pieces, stitched together
Fully generated levels can feel random in a bad way. So many games mix: designers build small pieces by hand, and the generator picks and arranges them.
Spelunky (2008) builds each level as a 4 by 4 grid of rooms. It first lays a guaranteed route from a room in the top row down to an exit at the bottom, then fills each room from hand-made templates, with some random changes.
Hyper Shards can do the same: the team designs 30 short wave pieces using teach, test, twist from the Level design lesson, and the generator orders them by difficulty, with a rest piece before every boss.
When it helps, and when it bores
Procedural generation is great for replay: a small team can give players thousands of different runs.
It can also feel samey. Designer Kate Compton calls this the 10,000 bowls of oatmeal problem: every bowl is technically different, but to the player it is all just oatmeal. A new star field that changes nothing about how you play stops feeling new very fast.
So generate the things that change decisions, like map layouts and wave mixes, and hand-craft the big moments players will remember, like bosses and Sprig's first bloom.
Bolt says: Next lesson: 60 frames per second, and how to keep a busy, generated wave running smoothly.
Fact-checked 9 October 2026
- MDN: Math.random() developer.mozilla.org
- Wikipedia: linear congruential generator en.wikipedia.org
- Wikipedia: Perlin noise en.wikipedia.org
- Wikipedia: procedural generation en.wikipedia.org
- Wikipedia: Rogue en.wikipedia.org
- Wikipedia: Spelunky en.wikipedia.org
- Minecraft Wiki: seed minecraft.fandom.com