How do video games make random numbers?
How do video games make random numbers? They almost never roll real dice. Instead, they run a small piece of math that turns out a long string of numbers that look random but follow a fixed rule. In this post you will see how that math works, what a seed is, how raw numbers turn into drops and spawns, and how one free browser game uses randomness to build fair arenas.
How do video games make random numbers? The short answer
A game keeps one number in memory, called the state. Every time it needs something random, it runs the state through a formula, gets a new number, and saves that new number as the state. The output looks scattered, but if you start from the same state you get the same list every time.
That starting state is the seed. The formula is a pseudorandom number generator, or PRNG. Everything you call "RNG" in a game, from a critical hit to a rare drop, comes from this loop.
Why computers cannot roll real dice
A processor is built to do the same thing every time. Give it the same input and it gives you the same output. That is what makes software reliable, and it is also why a computer cannot just "pick a number."
Numbers closer to truly random can come from hardware random number generators, which measure physical noise. A generator's seed is often taken from the state of the computer, such as the time, or from such hardware. After that, the formula takes over, because it is fast and repeatable.
Pseudorandom number generators: the math behind game RNG
One of the oldest and best-known PRNGs is the linear congruential generator. The rule is simple: multiply the state by a number, add another number, and keep only the remainder after dividing by a third number.
Try a tiny one by hand. The rule is next = (5 × current + 3) mod 16, and the seed is 7.
- 5 × 7 + 3 = 38. 38 mod 16 = 6.
- 5 × 6 + 3 = 33. 33 mod 16 = 1.
- 5 × 1 + 3 = 8. 8 mod 16 = 8.
- 5 × 8 + 3 = 43. 43 mod 16 = 11.
- 5 × 11 + 3 = 58. 58 mod 16 = 10.
- 5 × 10 + 3 = 53. 53 mod 16 = 5.
The sequence 6, 1, 8, 11, 10, 5 does not look like it follows a pattern. But start again from 7 and you will get exactly the same six numbers. With only 16 possible states, it repeats quickly. Real generators keep far more state: the widely used Mersenne Twister repeats only after 2 to the power 19937, minus 1, steps.

Newer families, such as the xorshift generators from 2003, work the same way: a fixed rule, a hidden state, and output that passes for random.
Seeds: how one number creates a whole world
Because a PRNG is repeatable, a single seed can stand in for an entire level. A game does not need to store a map. It can store one number, feed it to the generator, and rebuild the same map whenever it wants. That is the core trick behind procedural generation in video games.
Seeds are also useful for testing. If a bug only shows up on one map, a developer can save the seed and reproduce the exact run.
From raw numbers to loot drops, crits, and enemy spawns
A PRNG gives you a big integer or a fraction between 0 and 1. Game code then shapes it into a decision. Here are the common patterns:
- Pick one of N. Multiply a fraction by N and round down. For six possible items, you get a whole number from 0 to 5, each equally likely.
- Roll against a chance. For a 15% critical hit, draw a fraction and check if it is below 0.15.
- Weighted tables. Give each item a weight, add them up, draw a number in that range, and walk down the list until you pass it. Common items get big slices, rare ones get thin slices.
- Random positions. Draw an x and a y, then check the spot is legal. If it is not, draw again.
Randomness also shapes behavior. An enemy can pick where to go by mixing a fixed goal with a random roll, and then use pathfinding to get there. The roll keeps enemies from moving like a train on rails.
Fair vs random: rerolling what is unfair
Pure randomness can produce results nobody wants, such as a level with no way through. A common fix is to generate something, test it against a rule, and throw it away if it fails. You will see that pattern for real in the next section.
How Tank City Reboot uses randomness in every match
Tank City Reboot is a free site with two original tank games that run in your browser. Both use randomness, but in different places and for different jobs.
The first game: fixed stages, random rewards
The six stages of the first game are hand built. The maps and the 20-tank lineup for each stage are fixed, so you can learn them. Randomness shows up in the rewards and in enemy choices:
- The 4th, 11th and 18th tank of every stage carry a power-up and blink. Which tanks carry one is not random, so you always know when to look.
- When you hit a carrier, the power-up it drops is one of the six kinds at random, and it lands on a random spot. That is the "pick one of N" pattern and the "random position" pattern together.
- Malware tanks head mostly for the CPU core, sometimes for you, and sometimes anywhere. That mix works like a weighted choice: a strong bias toward the goal, with enough variety that you cannot predict every move.
So the luck is in what you get, not in the challenge itself. A Garbage collection drop that wipes the field feels very different from a Backup life, and you never know which one is coming.
Zero Day: a seeded arena every wave
Tank City Zero Day, the second game, generates a fresh arena for every wave. Each arena is 13 by 13 tiles and is drawn from a seed, which is the same idea as the hand-worked generator above: one number in, one whole map out.
The generator follows rules so the map is playable:
- The arena is a mirror image left to right, so neither side is luckier.
- It always keeps clear the three enemy gates on the top row, your start spot and the wall around the CPU core.
- Then it runs a fairness test. Every gate and your start must be able to reach the core by going around silicon and coolant. Firewall counts as open, because any tank can shoot through it. If the test fails, the arena is drawn again.

That last rule is the reroll pattern from earlier, used for real. You get a new layout each wave, but never one where an enemy is sealed off or you are boxed in.
Between waves, a menu called Patch Tuesday offers upgrade cards drawn from the upgrades you have not maxed out yet. About 1 offer in 5 draws two upgrades instead of three, and whenever fewer than three are drawn, a Two-factor card (one extra life) fills the gap. That is a small piece of odds bending: the menu never comes up short.
Not everything in Zero Day is random. Points, hits to destroy each threat, and the chain multiplier are fixed rules. Every kill within 2.5 seconds of the last one adds to your chain, up to a multiplier of eight. Your skill sets the score; the seed sets the stage.
Frequently asked questions
Are video game random numbers truly random?
Almost never. Games use pseudorandom number generators, which produce numbers that look random but come from a fixed formula, so the same seed always gives the same sequence.
What is a random seed?
A seed is the number that starts a pseudorandom number generator. The same seed always produces the same sequence, which is how one number can rebuild a whole level.
Do games use the same seed for every player?
It depends on the game. A seed is often taken from something like the clock, so each run differs; a game that wants everyone to face the same challenge can share one seed.
How do browser games generate random numbers?
The same way: a pseudorandom generator inside the game's code, often seeded so a level can be rebuilt from one number. For how games run in the page itself, read what WebGL is and how games run in a web browser.
Get started
Want to feel the difference between fixed and random? Play a few stages of the first game and watch which power-ups the carriers drop. Then switch to Zero Day and notice how each wave's arena changes but always leaves a way to the core. Both games run in a current Chrome, Edge, Firefox or Safari with WebGL 2, and each one remembers your best score in that browser.
Play Tank City Reboot: it is free, plays in your browser on a computer or a phone, and needs no account.
Comments
No comments yet.
Sign in or make an account to comment.