May 24, 2021
4 mins read

Random number generator in online games

technology keyboard lighting candy
Photo by Lucie Liz on Pexels.com

In case you’ve ever wondered, online games use random number generators. A random number generator (RNG) is an algorithm that produces random-dependent numbers. In video games, these random numbers are used to determine random events such as throwing a dice, cards from a chest, rewards from a game and more.

For example, in the Heartstone  game there are some gameplay mechanics that are based on getting random cards at a fixed cost or variable cost. You can also open envelopes and you get 5 different cards each time you do so with a certain probability depending on the type of card it is. Or in  Clash Royale there are several types of reward chest that give you an x-chance to get a Legendary Card or cards of any kind.

What I write in this article is an assumption of how these games work, you can’t say that’s 100% so (you’d have to ask the developer) but it’s a possible explanation of how these random number generators work in online games.

Pure random numbers

A succession of random numbers is characterized by no rule or plan that allows us to know its values. There are random digit tables obtained by physical processes such as lotteryes, roulette, etc.. On the page random.org to create these random numbers and an example can be seen in Fig. 1.

generador de números aleatorios
Figura 1. Random integer generator

These pure random numbers have several drawbacks such as:

  • It is advisable to know its distribution.
  • The generated data should be identically distributed independently.
  • Reproducivity, a previously generated sequence cannot be played back.
  • They may require table storage because their values change each time.

How a random number generator works

Simulation is to perform experiments with a model with the aim of decoupling information under certain conditions. I’ll focus on the case of stoic simulation. Conclusions are usually obtained by repeatedly generating simulations of the random model.

Pseudorandom numbers that simulate the realizations of a random (uniform) variable are often used due to the drawbacks of pure random numbers. Most simulation methods are based on the possibility of generating pseudorandom numbers with uniform distribution between 0 and 1.

A random number generator is obtained by a recursive algorithm called a generator:

 x_i = f(x{i-1}, x{i-2}, ..., x{i-k})
[cool_tag_cloud smallest=”10″ largest=”20″]

where

  • k generator order.
  • (x0, x1, …, xk-1) seed (initial state).

Succession numbers will be predictable from the seed, knowing the algorithm and seed. However, if this were not known, a series of pseudorandom numbers could not be distinguished from a succession of truly random numbers.

Problems encountered in the past

Serious problems of precedence have been encountered in the past. That is, you can predict the result of a random number generator and this is not desirable. An example was the work done by researchers on the RNG of the Windows operating system. This work analyzed the randomness of the generator, of the algorithm that Windows used to generate random numbers. Result was that they weren’t really random numbers.

Therefore, the generator was running in user mode instead of kernel mode, and therefore it is easy to access its state even without administrator privileges. Initial values of part of the factory state are not explicitly set, but are defined by the values present in the stack when the generator is called. In addition, each process runs a different copy of the generator, and the state of the generator is updated with system-generated entropy only after generating 128 KBytes of output for the running process.

Algorithms used in random number generator

There are a lot of algorithms to generate random numbers between them:

  • Average squares. The algorithm is to choose a number of 2n digits. For example n equals 2, therefore we must choose a number of 4 digits. I choose  4545  and square it up with an 8-digit number. Results in 20657025. The number resulting from selecting the 2n central figures of the previous result is named X1. Pseudorandom number would be  0.6570. The number is between 0 and 1.
  • Lehmer. It is a type of linear congruencial generator (LCG) that operates in a multiplicative group of n-module integers. That is, it is a sequence of pseudorandom numbers calculated with a linear function defined to dashed chunks.
  • Outdatedrecords. It is based on multiple resource linear generators.
  • Combinations.

The source code is available in many online libraries such as:

Use in online games

Random number generation, or RNG, is a decisive factor in many modern games. They’re the reason you always come up with unique rewards, why Hearthstone or   Clash Royale cards are different every time you get them, and why you randomly find a great treasure (or not) in  Diablo. Some procedurally generated games, such as  The Binding of Issac  or  Minecraft,would not even be possible without RNG.

The process would more or less be like this. The game launches a request to get a random number, and assigns that random number to a result or item. If a card tells you that you get 3 random minions at cost one, what the game does is make a request to a scheduled pseudorandom number funion, and gets 3 numbers, and each number is assigned a cost card one.

Summary

In conclusion, it’s not your fault that you get distressed random cards and think your favorite game sucks. It’s all due to RNG, or if you want the most appropriate term, pseudorandom number generator or deterministic random bit generator.

No matter how much you train, it all depends on throwing a digital dice that you don’t see. Older games were very predictable and limited in terms of where the RNG was placed, so handling was very easy. Newer games now want randomization to look random as random as much as possible. The next time you blame RNG, or the god of the RNG, it won’t be them, that’s how it was programmed.

References random number generator

  • https://en.wikipedia.org/wiki/AMillionRandomDigitswith.
  • https://www.random.org/integers/
  • http://www.fourmilab.ch/hotbits/
  • https://eprint.iacr.org/2007/419
  • https://es.wikipedia.org/wiki/Caja_de_recompensas
  • https://medium.com/@naomijoyce/random-number-generation-in-video-games-dda985c5652f
User Avatar

Avelino Dominguez

👨🏻‍🔬 Biologist 👨🏻‍🎓 Teacher 👨🏻‍💻 Technologist 📊 Statistician 🕸 #SEO #SocialNetwork #Web #Data ♟Chess 🐙 Galician

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

technology keyboard lighting candy
Previous Story

Generador de números aleatorios en juegos online

black and silver laptop computer on brown wooden table
Next Story

Cómo funciona la encriptación en internet

Top

Don't Miss