← /browse

Making Games / 4 min /

What is procedural generation? Seeds and caves explained

Procedural generation lets a game build levels from a few rules instead of storing every tile. Here you grow a cave yourself: scatter random walls, smooth them with a neighbour rule, and see why the same seed always gives the same map.

Learn what a seed is, why caves form, and how designers tune a single number to change how a level feels. A good first idea for anyone curious about making games.

A cave map of coral floor and dark rock squares beside the title What is procedural generation?

Games that build themselves

Some games hand you a map someone drew by hand. Others build the map while you watch: a new dungeon every run, a world that exists the moment you type in a name. That is procedural generation: instead of storing every tile, the game stores a small set of rules and lets the computer apply them.

It is one of the most useful ideas for anyone who wants to make a game, because a few lines of code can produce more levels than you could ever draw. The classic dungeon game Rogue (1980) already built its levels this way, and the whole "roguelike" genre is named after it.

Random, but not really

When code asks for a "random" number, it does not roll a die. It runs a formula that starts from a number called the seed and spits out a long list of numbers that look random. The trick: the same seed always gives the same list.

That is why a procedural game can be fair and shareable. Games like Minecraft let you type a world seed; give the same one to a friend and you both get the same world. The game never has to save the world's shape, only the seed (and your changes).

Grow a cave in three steps

One well-known recipe for caves is called a cellular automaton, which sounds fancy but is just a grid where every square looks at its neighbours:

1. Scatter. Fill the grid with random walls. Each square becomes a wall with a chance you choose. At this point it is pure noise, like static on a TV.

2. Smooth. Every square counts its eight neighbours. If five or more are wall, it becomes wall; otherwise it becomes open floor. Do this once and the noise starts clumping into blobs. Do it a few times and the blobs become cave-like rooms and tunnels.

3. Check it. A real game also tests that the player can walk from the start to the exit, and throws the level away if not. Random does not mean careful.

What you just saw

Notice how the wall chance matters. After a few smoothing steps, a low setting like 30% leaves an almost empty hall, around 45% gives open caves with clumps of rock, and 60% fills the map with big solid areas and small pockets of floor. Designers tune that one number until the levels feel right.

Also notice that a new seed gives a different cave from the same rules, while the same seed always rebuilds the same one. Game makers use this all the time: a daily challenge that is identical for every player is just one seed shared with everyone.

Why makers like it, and where it goes wrong

The big win is variety for free. A hand-built level takes hours; a generator makes a new one in a blink, so a short game can stay fresh for a long time. It also keeps downloads small, since the rules take far less space than a pile of maps.

The catch is quality control. A generator has no taste. It can produce a cave that is boring, a room the player cannot reach, or a level that is unfairly hard. That is why makers add checks (can you get from start to exit?), tune the numbers by hand, and often mix generated space with hand-made set pieces. Players call a game "samey" when its generator has too few rules, and "unfair" when it has too few checks.

A useful habit is to keep the seed whenever something looks wrong. Because the same seed rebuilds the same level, you can come back to a broken cave, fix the rule, and test the exact same case again. A bug you can repeat is a bug you can fix.

Where else it shows up

Caves are only one use. Other typical jobs for procedural generation: scattering trees and rocks across a landscape, shaping hills with smooth "noise" functions, shuffling which rooms appear in a dungeon, and picking loot. Most big games mix it with hand-made parts, so the generator fills in the filler and people design the important places.

Try it in your own game

If you want to build your first generator, you do not need an engine feature for it. A grid is just a list of lists, a seeded random function is a few lines of code (the demo above uses one), and the smoothing rule is a loop over neighbours. Start tiny: generate a 20 by 20 map, draw it as coloured squares, and change one rule at a time to see what it does. Experimenting is the whole point.

More in Making Games

all Making Games →