Sponsored By

# Developing Games with Random Number GeneratorsDeveloping Games with Random Number Generators

In the olden days of Atari, developing games with Random Number Generators wasn't just hard - it was impossible. Today's programmers still have a similar problem: finding a true random. Let's review random number generators, when to use them and how.

Charlotte Walker, Blogger

October 21, 2014

5 Min Read

In the olden days (you know, the days of Atari), developing games with Random Number Generators wasn't just hard -- it was impossible. Most so-called "random" events were actually carefully calibrated to only create the illusion of randomness... and they could be hacked, by particularly clever gamers. Today's programmers still have a similar problem: finding a "true random." As our video games develop, there are more and more reasons for games to use random numbers.

Random Numbers: Not As Easy As It Seems

So... what's the problem? Can't a computer just pull a number out of a hat? Well, no, it can't. When we roll a properly balanced six-sided die, we have an equal probability of landing on 1, 2, 3, 4, 5 or 6. But a computer can't just roll a die in an ordinary world: a computer needs to use some sort of procedure to find a number. That's just how computers are built. Many computers today have specific chips that are designed to generate random numbers, but that doesn't necessarily mean that they are truly random.

Most numbers used in games are pseudo-random numbers. They seem random enough, but they are not really random. To generate true random numbers, computers need to use environmental input that is inherently random, such as a user's keystrokes. But the flaw inherent to this is obvious: if the random numbers are generated with a specific platform, they could potentially be controlled.

What can you do with randomness?

Random number generators are continuously used for more and more gaming functions and algorithms. Randomness allows you to make your games less ‘determined’ and thus more difficult for the player to beat, which means less patterns and more potential for replay.

Among other reasons, you can use random number generators for:

• Unit stats: Give random stats to enemies instead of cloning the same level of difficulty on every single enemy encountered. Fixed values for Attack, Defense, Speed, Damage, etc. can create a boring gameplay pattern. Random ranges of values will generate stronger and weaker versions of enemies, or even friends.

• Map generation: You can hand draw the map if you choose to, but if you want to create an unpredictable and complex game, a random map will be a better choice. It also saves you time – no need to design piece by piece; the random generator will do the work for you.

• Sprite generation: Randomly place pieces together to create sprites rather than hand-drawing every sprite in your game. If you have ever played around with avatar options, like those of Skyrim, you can see the potential to create thousands of different sprites or character designs with random generators. The same thing can be done for buildings, cars, trees, etc.

• Artificial intelligence: Allow your AI to make a random rather than a fixed decision, making the gameplay less predictable to the player.

A great example of randomness at work. Spelunky: randomly generated levels, randomly selected tiles and randomly populated enemies

Random Numbers in Games

Random numbers appear everywhere in games, from the online slots games to MMORPG games like World of Warcraft. In video games, random "drops" of items often significantly affect the course of the game. Racing games may use random number generators to determine how fast or slow the other cars move, card games may use random number generators to shuffle the deck. Some popular kids games, such as Pokemon, are almost entirely driven by encounters which are attached to random number generators. In fact, you would be hard-pressed to find a game today that does not include random number generators in some form.

Click on ‘Create New World’ in Minecraft and behold a beautiful example of random number generation algorithms creating a ‘random’ and exciting new world to mine and develop.

In slots games and other games of chance, the random number generator is absolutely essential. An improperly coded random number generator could potentially payout more often than it should (or not at all). A great example are Gaming Club slot machine games which use pseudo-random numbers rather than true random numbers to control the game without allowing players to predict when a certain number will be hit. This is a real concern: there have been players who have figured out the equation of gambling games and been able to predict the outcomes of their games. So programmers who intend to design slot machine games need to be especially careful.

Slots and card games like the ever-popular Hearthstone depend on pseudo-random number generators.

Implementing Random Number Generators within a Game

When developing a computer game, the programmer begins by creating a seed number. This seed number is used by the computer to create another number, which is random and generated by a computer chip on the compiling computer. Each time a new number is generated, it is built upon these numbers -- so each subsequent number is truly random. However, there is something important to note: the seed number itself can be used to generate all subsequent numbers. Should someone discover the seed number, they could then (potentially) game the system. But in online gaming, the risk of this is fairly low.

Random numbers are a surprisingly interesting area of programming. Though at first they may seem very simple, they are actually quite challenging to both create and work with. They are also an absolutely essential component to online games of chance. Programmers interested in developing video games may want to do a little research into random numbers before they proceed to ensure that their games cannot be manipulated.

More information about random number generation in different programing languages:

Read more about:

Featured Blogs

## About the Author(s)

Daily news, dev blogs, and stories from Game Developer straight to your inbox

You May Also Like