Random Number Tips
How Random Number Generators Work in Games
RNG means random number generator. Games use a generator to produce a value and a separate rule to decide what that value means. A result from 1 to 10 might become movement, a card draw or a bonus. To understand the odds, look at both the numbers the generator can return and the game’s rule for mapping those numbers to an outcome.
What a seed does
Many games use a pseudorandom number generator. It starts in a state initialized from a seed and advances the state each time it produces a value. With the same algorithm, starting state and sequence of calls, the same results can be reproduced. A developer can use that when testing a generated map or replaying a bug. For example, Unity documents how to set a seed in its Random.InitState API. If one additional draw happens before the map is built, the rest of the draw sequence can shift.
An even draw can produce uneven odds
Imagine the game draws an equally likely integer from 1 to 10 after each round and uses this table.
| Draw | Event | Chance |
|---|---|---|
| 1–6 | Take a coin | 6 out of 10 |
| 7–9 | Move again | 3 out of 10 |
| 10 | Draw a bonus card | 1 out of 10 |
The coin has six slots and the bonus has one. To make the bonus happen 20% of the time, give it 9 and 10 and let 7–8 trigger the extra move. This changes the rule table while leaving the underlying range unchanged.
Why a random result can show up twice
In the example, if each draw is independent, a bonus this round leaves the chance of a bonus next round at one in ten. Two bonuses in two specified consecutive rounds have a one-in-100 chance. Repeat draws can also happen to ordinary outcomes, such as three coins in a row. A game can change its rules after a draw if it wants a different experience. In a ten-card deck with only one bonus card, keeping that card out makes a second bonus impossible until the deck resets.
You can see how the table works with Lucky Step, a free iPhone and iPad integer picker. Set 1–10, write down ten results, then apply the mapping to the list by hand. A ten-draw sample may contain no bonus at all, or more than one. This illustrates the game rule and short runs of results. The table and seed example describe general game design rather than features or internals of Lucky Step.