




Anybody into RPGs on the old portable game systems of yester-year probably remembers Golden Sun. Golden Sun was one of the best on the Gameboy Advance. Great music and graphics complemented a unique battle system and large game world. So... let's turn on the game. I know that I have to go to the left, so I'll just load the game and hold left to get where I need to go... and...

A random battle with a Dirty Ape begins, with my party getting a first strike. Well, maybe I don't feel like fighting a Dirty Ape today. I'll just restart the game. I'll turn the power off and turn the power on. Now, I'll just load the game, hold left to get where I need to go... and... again... in the EXACT same spot the enemy appeared the first time, I see:
Again, I get attacked a Dirty Ape, with a preemptive strike. That's really strange. In fact, no matter how many times I restart, if I follow the exact same steps I will always get the exact same enemy, and have the opportunity to attack first. That's a little... odd. However, things like this are actually more common than you'd think in video games (especially older ones).
When a person is playing Snakes and Ladders, or even a game like Monopoly, they're relying on dice to make the game movements random. By rolling a die, they get a random number from 1 to 6. Most of the time the value on the die is simply how many spaces someone moves ahead. In old paper RPGs and many other more complex non-board games, dice from 1 to 20 or higher are used to provide an even larger possible set of random outcomes. These random numbers can be used to represent how much damage a character does to an enemy or whether they are to get poisoned or not when drinking a potion or other such things. So your character drinks a potion, you roll a die and if it's over a certain number you survive. Things like that.
Now, think about a video game. You walk around a forest and suddenly a random enemy appears. In the same way as a board game, it uses random numbers to determine when these kinds of things happen, or which random events occur. It doesn't, unfortunately, have any way to roll a die or flip a coin. So it's going to have to come up with other ways.
Now, software lives in a very dark box and generating random numbers takes some thought since it can't flip a coin or throw a die, and everything in the software itself is non-random. All the software inside the cartridge knows is what it is, what it can calculated, and what is given to it in the form of input. How is it going to generate randomness in a situation like this? It can't look at itself, since the code will always be the same. It can't look at what it can calculated because without outside influence it will always calculate the exact same things. That only leaves one place for it to look. It's going to have to look outside itself, and rely on the unpredictability of its inputs.
Let's try an experiment. I'll turn Golden Sun on, and instead of just holding left the whole time, I'll press 'up' once while walking, and then resume holding left.
This time I was attacked by a Warrior Bee instead, though still getting to attack first. Very interesting. The simple fact of changing my character's walk to include moving up slightly changed what random enemy would appear. It seems to suggest that what buttons I press impacts the random number generation in the game. Also very interesting is the fact that every single time I get attacked after powering on, no matter my walking pattern, I get to attack first. Strange...
Golden Sun, it seems, has two different random number routines. One that is involved in the outside world, deciding if/what enemies attack, and another one that is involved in random battle events (such as whether you get a preemptive strike, when you miss an attack, or whether you get a random item dropped). Since what walking pattern or enemy doesn't seem to impact whether I get a first attack (I always do after I power on and load), they don't seem to impact each other either.
The first random system, the outside world random numbers, seem to be in some state that is constantly changed by user actions. This is a common way to do things in games, but isn't really efficient. It means that adds extra processing that has to be done every time any action is taken. The second type, the battle random numbers, actually follow a more regular method in programming: following numbers in a mathematical pattern.
Most simple random number generation in older games is done using a simple mathematical pattern that takes the previous random number, does some math with it, and then produces a new number. Essentially it's a pattern of numbers that, after a long time, repeats. It has the benefit of not needing to be recalculated every time the user does anything. It only has to do processing if a new random number is needed. Usually, however, to prevent it from being too predictable and starting at the same point every time, they do what is called 'seeding' of the random number generator, which is the start the pattern with an unpredictable value, such as the current time in milliseconds, or for older system such things as how long the player took to press the 'start' button to begin.
However... Golden Sun didn't do that. When a game is loaded, it's in a predictable state. Always the same.
Most of the time, even using very simple systems for random generation, even a predictable one, doesn't negatively impact a video game. Usually things are flying around the screen quickly and nobody is going to notice whether an enemy's attacks are only semi-random. However, there are some exceptions. Golden Sun is probably one of the better known games to suffer from a completely predictable random number system to the point where it can be abused. By restarting your Gameboy and following a very specific set of steps, you ensure the random number generator is in such a state as to ensure you get very rare item drops from enemies every time.
In fact, people have written guides on how to exploit this system to ensure you get extremely rare items.
Golden Sun isn't alone though. Even games as recent as Final Fantasy 12 have had people figure out ways to manipulate the randomness state in attempts to cheat the system. Why a game that new wouldn't use time or other factors to initialize its random number generator's state, or save its state with each save file so as not to be as easily known, is beyond me.
For most games, especially newer ones, this isn't much of a problem. Systems now have full real-time clocks on board and most games simply use the current time, to the millisecond, to seed their random number generators. So I'd imagine this isn't an issue that you will see much of going forward, but it's good for learning about some of the flaws in random number generation.
Now, just for accuracy, I should state that none of the numbers generated by these random number generators are truly 'random' as they're determined by outside factors and are calculable. In fact, in more serious literature what people usually refer to as random number generators are actually called pseudo-random number generators, to highlight the fact that they only look random to the naked eye. For the most part though, when people talk about randomness in games they're usually talking about unpredictability for the player and not randomness at a philosophical level, so I feel it's still a justified use of the term.