Gamasutra is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Gamasutra: The Art & Business of Making Gamesspacer
arrowPress Releases







If you enjoy reading this site, you might also want to check out these UBM Tech sites:


 

Developing Games with Random Number Generators

by Charlotte Walker on 10/21/14 02:00:00 pm   Featured Blogs

3 comments Share on Twitter    RSS

The following blog post, unless otherwise noted, was written by a member of Gamasutra’s community.
The thoughts and opinions expressed are those of the writer and not Gamasutra or its parent company.

 

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:


Related Jobs

innogames
innogames — Hamburg, Germany
[08.14.20]

Java Software Developer
Wooga GmbH
Wooga GmbH — Berlin, Germany
[08.14.20]

Unity Game Engineer
innogames
innogames — Hamburg, Germany
[08.14.20]

Expert / Senior Java Software Developer - New Mobile Game
Disbelief
Disbelief — Cambridge, Massachusetts, United States
[08.13.20]

Programmer





Loading Comments

loader image