# Procedural Generation in Games: How It Works
Source: https://thelockoftime.world/blog/procedural-generation-in-games
What procedural generation is, the types and algorithms games use to build levels and worlds, and how it differs from plain random generation.


Procedural generation is a technique where a game creates its content — levels, terrain, loot, enemies, whole planets — using algorithms and rules at runtime, instead of a designer placing every piece by hand. Feed the system a starting number (a **seed**) and it assembles a fresh, playable result that stays inside the boundaries the designers set.

It's why a roguelike can hand you a different dungeon on your hundredth run, and why Minecraft can generate a world with more surface area than the Earth. Below is what the term actually means, how the algorithms work in plain language, and where the whole approach breaks down.

## What is procedural generation?

The word most people reach for is "random," and that's the misconception worth clearing up first. Procedural generation is closer to **curated randomness**. Designers build the raw materials — room templates, tile sets, item pools, enemy types, terrain rules — and write instructions for how those pieces fit together. An algorithm then combines them, usually starting from a seed, into something new that still obeys the rules.

So when a game is described as *procedurally generated*, it doesn't mean the developers threw dice and shipped whatever came up. It means they authored a system that assembles content on the fly, rather than authoring each finished level directly. The seed is the key detail: the same seed always produces the same output, which is why players can trade seed codes to replay a friend's exact world, and why a developer can reproduce a bug by re-running the layout that caused it.

The craft lives in the constraints. A weak system produces mush; a strong one produces variety that still feels intentional.

## Procedural generation vs random generation

These get used interchangeably, but they're not the same thing, and the difference is the whole reason procedural generation works.

**Random generation** picks values with no rules attached. Roll for a number, place a wall, move on. Left to itself, that approach happily seals the exit behind an unbreakable wall, drops you into a room with no doors, or stacks three elite enemies on the starting tile.

**Procedural generation** wraps that randomness in rules and constraints applied to curated pieces. It might still roll for a room, but it checks that a path exists from entrance to exit, that the loot on offer is winnable-with, and that the difficulty lands in an acceptable band. Randomness is the engine; the constraints are the steering.

Put simply: randomness is a coin flip, procedural generation is a coin flip with a designer standing over it saying "not that one." Every good procedural system is really a set of guardrails around a random number.

## Types of procedural generation

"Procedural generation" is an umbrella. Games apply it to very different parts of their content, and most big titles use several kinds at once.

- **Levels and dungeons.** The classic use. Roguelikes like Spelunky, [Dead Cells, and The Binding of Isaac](/blog/best-roguelike-games) stitch a new layout from handcrafted rooms each run, so the space you're learning to read is never quite the same twice. This pairs naturally with [permadeath](/blog/what-is-a-roguelike), since a fixed map plus permanent death would just be a memory test.
- **Terrain and worlds.** Minecraft, No Man's Sky, and Valheim generate landmasses, biomes, caves, and planets from math rather than sculpting them. This is what makes effectively endless worlds possible for a small team.
- **Loot and items.** Diablo and Borderlands roll weapon and gear stats from tables — base type, modifiers, rarity — so two guns of the "same" model can play completely differently. The famous "Borderlands has 87 bazillion guns" pitch is procedural loot in a nutshell.
- **Textures and models.** Noise functions can paint marble, wood grain, clouds, or rust without an artist hand-drawing every pixel, and can scatter rocks, grass, and trees across a map.
- **Quests and narrative.** The rarest and hardest kind. Dwarf Fortress simulates entire histories — wars, migrations, grudges — while the AI Director in Left 4 Dead reshapes enemy waves and item drops on the fly to keep tension high. Narrative generation is where procedural systems most often show their seams.

## Common algorithms and techniques

You don't need to write these to understand what a game is doing. Here are the workhorses, in plain terms.

- **Noise functions (Perlin, Simplex).** Instead of raw random values that look like static, noise produces smooth, natural-feeling gradients. Sample it across a grid and read the values as heights and you get rolling hills, mountains, and valleys — this is the backbone of nearly every generated landscape, Minecraft included. Simplex is the faster, less grid-biased successor to Perlin.
- **Cellular automata.** Start with a random scatter of "wall" and "floor" cells, then repeatedly apply a simple neighbour rule (a cell becomes a wall if enough neighbours are walls). After a few passes, the noise settles into organic-looking caves. It's the go-to trick for natural cave systems.
- **BSP and room-and-corridor.** Binary space partitioning recursively slices a rectangle into smaller rectangles, drops a room into each, and connects them with corridors. It's the reliable, readable method behind a lot of classic dungeon layouts.
- **Wave function collapse.** A newer favourite. You give it a small sample of tiles and the rules for which tiles may sit next to which, and it fills a whole map so every local placement stays legal — like solving a Sudoku made of art tiles. Great for coherent towns, dungeons, and patterns.
- **L-systems.** A rewriting grammar that starts with a symbol and repeatedly expands it by rules. Point it at branching structures and it produces convincing trees, plants, river networks, and lightning.

Most real games chain several of these: noise for the terrain, cellular automata for the caves inside it, an L-system for the forests on top.

## Why games use it

- **Replayability.** If the levels and loot change every run, the game stays unpredictable long after you've mastered its systems. This is the beating heart of the [roguelike](/blog/what-is-a-roguelike) and its lighter cousin the [roguelite](/blog/what-is-a-roguelike).
- **Scope.** Hand-building a world the size of Minecraft or No Man's Sky is flatly impossible. Procedural generation lets a small team ship a near-infinite amount of space.
- **Storage.** A generated world barely exists on disk — you store the seed and the rules, not the finished terabytes. No Man's Sky fits eighteen quintillion planets into a normal-sized download because it stores the recipe, not the meals.
- **Surprise.** Even the developers don't know exactly what a given seed produces, so the game can still surprise the people who made it.

## The trade-offs

The cost is authored intent. A hand-built level can have a deliberate rhythm — a quiet stretch before an ambush, a view framed just so, an enemy placed to catch you exactly when you're low on health. A generated one trades some of that craft for variety, and when the constraints are weak the result feels samey, "soulless," or incoherent, like a puzzle assembled from mismatched pieces.

The honest failure mode is the "wide but shallow" world: technically endless, emotionally flat. No Man's Sky at launch is the cautionary tale — quintillions of planets that started to blur together after a few dozen.

That's why the strongest procedural games are usually **hybrids**. Spelunky and Dead Cells generate the overall layout but assemble it from rooms a human designed and tuned, so every run is fresh yet every room is fair. The generator handles arrangement; a person still handles the craft inside each piece. Even Dwarf Fortress and Caves of Qud, about as procedural as games get, lean on hand-authored systems, art, and rules underneath — the generator multiplies the designers' work rather than replacing it. It also changes how [death and restarting feel](/blog/roguelike-death-mechanic): a generated world means starting over is a new problem, not a repeat of the last one.

In KUTO: The Lock of Time — our game — we sit on that hybrid end of the spectrum. The eras you fight through — Ancient Egypt, the Viking age, a neon cyber-city — are handcrafted layouts rather than fully generated ones, then varied so encounters with the Scythe of Kronos and your chosen time powers don't play out identically every attempt. It's authored space with room for variety, not a procedural roguelike. [Wishlist KUTO on Steam](https://store.steampowered.com/app/4755510).


## FAQ
**What is procedural generation in games?**
Procedural generation is when a game builds content — levels, terrain, loot, enemies — using algorithms and rules at runtime, instead of a designer placing every piece by hand. Fed a starting number called a seed, the system produces a fresh, playable result that stays inside the boundaries the designers set.

**What are the types of procedural generation?**
The common types are level and dungeon layouts (roguelikes like Spelunky), terrain and whole worlds (Minecraft, No Man's Sky), loot and item stats (Diablo, Borderlands), textures and models built from noise, and quests or narrative events (Dwarf Fortress, the AI Director in Left 4 Dead). Most games mix several of these.

**Is procedural generation the same as random generation?**
No. Random generation picks values with no rules attached; procedural generation applies rules and constraints to curated building blocks. Pure randomness can wall off an exit or stack an unwinnable fight — a procedural system guarantees the result is completable and fair within its intended difficulty.

**What algorithms are used for procedural generation?**
The staples are noise functions like Perlin and Simplex for terrain height, cellular automata for organic caves, BSP and room-and-corridor for dungeons, wave function collapse for tile layouts that obey local rules, and L-systems for branching structures like trees and rivers.

**What is a seed in procedural generation?**
A seed is the starting number fed into the algorithm. The same seed always produces the same output, which is why players can share seed codes to replay each other's worlds, and why developers can reproduce a specific layout to debug it.

**Why do roguelikes use procedural generation?**
Run-based games need fresh content each attempt. A fixed map turns dozens of restarts into a memorisation exercise, so procedural generation makes each run a new problem to solve — which is what keeps the genre replayable after hundreds of hours.

**What are the downsides of procedural generation?**
The cost is authored intent. A hand-built level can carry a precise rhythm and a perfectly placed enemy; a generated one trades some of that craft for variety. Weak constraints produce content that feels samey or incoherent, which is why most studios blend handcrafted pieces with generated assembly.

**Does KUTO: The Lock of Time use procedural generation?**
KUTO sits on the hybrid end. Its eras — Ancient Egypt, the Viking age, a neon cyber-city — are handcrafted layouts rather than fully generated ones, then varied so encounters with the Scythe of Kronos and your time powers don't play out identically every attempt. It is authored space with room for variety, not a procedural roguelike.