Programming and Engines

Random Numbers and Seeds in Games

How computers produce random-looking numbers, what a seed does, and how seeds let players share the same generated world or replay a run exactly.

On this page
  1. Random, but not really
  2. A tiny generator by hand
  3. Turning numbers into game events
  4. What seeds make possible
  5. Where seeds come from
  6. Ways it goes wrong
  7. Fair randomness versus felt randomness
  8. A note on chance and money

Random, but not really

When a game rolls for a critical hit or builds a new dungeon, it needs numbers that feel unpredictable. A computer, however, follows instructions exactly, so it cannot produce true chance on its own. What it does instead is use a formula that generates a long sequence of numbers that look random. These are called pseudo-random numbers.

The key property is that the sequence is completely determined by where it starts. That starting value is the seed. Give the formula the same seed and you get the same sequence, in the same order, every time.

A tiny generator by hand

Real generators use more elaborate formulas, but a small example shows the principle. Take this rule: multiply the current number by 5, add 3, then keep only the remainder after dividing by 16. Start with a seed of 1.

  • 5 times 1, plus 3, is 8. Remainder when dividing by 16: 8.
  • 5 times 8, plus 3, is 43. Dividing by 16 leaves 11.
  • 5 times 11, plus 3, is 58. Dividing by 16 leaves 10.
  • 5 times 10, plus 3, is 53. Dividing by 16 leaves 5.

The sequence begins 8, 11, 10, 5. It looks scattered, yet anyone who starts from 1 and uses the same rule gets exactly those numbers. A different seed, such as 2, produces a different run. Because this toy rule can only produce 16 distinct values, it would soon start repeating. Real generators have enormously longer cycles, so repetition is not a practical concern in play.

Turning numbers into game events

A generator typically gives a raw number, which the game converts into something useful. To simulate a six-sided die, it might take the number, divide by 6, and use the remainder plus 1. To decide a 25 percent chance, it might check whether a value between 0 and 99 falls below 25. Over many repeats, the share of successes should hover near 25 percent, but short streaks of luck or bad luck are completely normal. Random events have no memory, which is why a streak does not mean the next result is due to change.

What seeds make possible

Shared worlds. In a game that builds its map from a seed, the world is not stored tile by tile. It is regenerated from the number. If one player types the same seed as another, both get the same layout. That is how people exchange interesting worlds with a short string of characters.

Replays. If a game records the seed and the player’s inputs, it can rerun the same session exactly, since every random event will fall the same way. This is useful for replay features, for demonstrations and for checking how a particular match unfolded.

Smaller saves. A generated world can be restored from its seed plus a list of changes the player made, instead of from a full copy. This is one reason save systems for large generated worlds can stay compact.

Reproducible bugs. A bug that appears only in some random situation is hard to fix. If a tester can report the seed, a developer can recreate the same situation on demand. Clear bug reports for randomized games therefore often ask for the seed.

Daily challenges. A game can set the seed from the calendar date, so everyone faces the same layout that day.

Where seeds come from

When a player does not choose a seed, the game usually picks one from something like the current time. Some games show it in a menu so players can note it down.

Ways it goes wrong

Different order of calls. The sequence is only the same if the game asks for numbers in exactly the same order. Suppose a visual effect also pulls a number from the same generator. If that effect fires on one machine and not another, everything after it shifts. Many developers therefore use separate generators for gameplay and for cosmetic details.

Version changes. If an update changes how the world is built from the seed, old seeds produce different worlds. Players who saved a favorite seed may be disappointed, and a save that relies on regeneration can break.

Different platforms. Math that is slightly different across devices can cause worlds or simulations to drift apart, a problem that matters especially for online games that rely on all players computing the same outcomes.

Weak generators. Simple formulas can leave visible patterns, such as numbers that fall in neat lines when plotted. For ordinary gameplay that is rarely an issue, but it is the reason developers use well-tested generators instead of inventing their own.

Fair randomness versus felt randomness

Players often feel that true randomness is streaky and unfair, so designers sometimes adjust it. A common approach is to give a rare drop a slightly higher chance each time it fails to appear, then reset it once it does. Another is to shuffle a bag of outcomes so that each one appears once before any repeats. These systems still use random numbers; they just shape them to match how people expect luck to behave. The thinking behind such choices connects to reward schedules, which explore how the timing of rewards affects players.

A note on chance and money

Random outcomes in a story-driven or skill-driven game are part of the design. When randomness is attached to real-money purchases, such as paid bundles with unknown contents, the situation is different. The outcome is uncertain, there is no guarantee of getting what you want, and spending can add up quickly. If a game offers such purchases, check whether odds are disclosed, set a clear limit beforehand, and treat the result as uncertain. The concept of how those mechanisms work is covered in neutral terms elsewhere, such as in the discussion of in-app purchases.

The complete guide to programming and engines

Programming Concepts Behind Games, in Plain Terms
Read the guide

Keep exploring

Guides from other topics

All topics →