RNGs (Random Number Generators) are the backbone of modern casino gaming, and understanding how they work can give players a significant advantage.
Casinos have always been a place where luck rules the day, and the thrill of the unknown draws millions of people every year to try their luck at games like slots, poker, and blackjack.
But behind the glitz and glamour of the casino floor lies a sophisticated mathematical system that determines every outcome.
In this guide, Dr. Catalin Barboianu, PhD with years of experience in mathematics and statistics, will break down the complex workings of RNGs, from the algorithms that drive them to the mathematics behind their outcomes.
Here’s what you’ll learn:
So, let's dive right in.
Every game of chance, including casino games, is required to be constructed to ensure two principles regarding 'chance':
The two principles say that chance has to be effectively and fairly served, and the luck factor has to be decisive in the games of chance, as their name suggests.
In common words, they say that the outcomes of the games of chance must be random. Randomness is a prerequisite for the existence and functioning of games of chance.
Keep in mind
The technical processes that generate the outcomes of the games of chance are devised to cancel any possibility for information about causes and initial conditions and for any rational reasoning, which together may determine the outcomes.
Such processes are:
They are characterized by physical features such as high speed, intensity, non-equilibrium, and/or non-visibility, thought to fulfill the role of providing the required randomness.
This role of generating the outcomes of the games in the condition of randomness was replaced in modern games by electronic devices and software simulating the original process while ensuring an accepted randomness.
Online casinos offer classical games in electronic versions, where outcomes (like spinning, shuffling, etc.) are generated electronically using a special software called a 'random number generator' (RNG).
In this guide, we shall see what randomness means, what random number generators are, how they function, and how they are used in the gambling industry.
You will be surprised that a precise definition of randomness, widely accepted in the scientific community, does not exist.
Definition
In common speech, randomness is meant as a disorder of the occurrences of the events for which causes are not known in their entirety.
This disorder reflects our lack of knowledge (or ignorance), which prevents us from predicting the occurrence of such an event. Hence, although the phenomenological world is deterministic, our reasoning cannot be deterministic regarding random events.
As such, randomness is first a feature of our reasoning and second of the world.
We can think of randomness as the opposite of rule, law, or purpose, as chaos, indeterminacy, irregularity, or a form of mutual independence.
But such characterization makes randomness a special type of disorder, a kind of total disorder. The 'total' attribute may be meant as 'equally possible' or 'equally unknown' or just 'independent' and makes randomness, in turn, to be an order.
Seeing randomness as both an order and a disorder should not twist our minds in any way; it's just the mere nature of randomness.
Although randomness looks like a mathematical concept and it is a primary concept for probability theory and statistics, it does not have a mathematical definition and has a philosophical dimension.
Mathematicians and philosophers struggled to provide such a definition from the beginning to the middle of the 20th century. Any possible mathematical definition was inconsistent with the nature of randomness as being related to experimental setups.
Remember
As a prerequisite for the existence and functioning of the games of chance, randomness should be retained as something not allowing predictability by two main features: independence of the outcomes – any outcome is independent of the previous and of the future outcomes; and unbiasing – individual outcomes, under the same experimental conditions, are equally possible and thus equally probable.
Keep in mind
Randomness is a philosophical concept that does not have a mathematical definition. It is meant as a total (or ordered) disorder that you cannot predict. In gambling, randomness ensures fairness between players and between the house and the players.
In general, a random number generator is any means (physical or electronic setup or device, or software) by which numbers in a set or interval can be randomly generated in a sequence, i.e., independently of the previously generated numbers (by no rule of determination) and uniformly distributed over the obtained sequence.
These 2 conditions: independence and uniformity – are accepted as effective features of randomness in real life, including gambling.
If you roll a die several times by hand and write down the results, we might think we have obtained a random sequence of numbers from 1 to 6.
This might be the case: independence is ensured, as the die is retaken in hand at each roll, and the die has no memory of its outcomes.
How about uniformity? One may raise the concern that some numbers occurred more frequently than others or two in a row.
While this kind of result could be just a hazard and wouldn't happen in the next, say, 100 rolls, nobody could eliminate the hypothesis that it could be as well a result of the specific physical factors of our experiment – maybe you throw the die repeatedly under about the same angle, with about the same speed, or from the same height, and this may cause specific faces to be favored.
We cannot know that for sure, so we cannot guarantee that this random number generator ensures uniformity.
As such, one may bet on rolling a certain number. However, the die roll as a physical setup may not be a trustworthy random number generator to use anywhere.
And yet some physical setups or devices ensure both accepted independence and uniformity. They are called hardware random generators or true random generators (TRNG).
Such hardware is based on special physical processes that occur at microscopic, atomic, and subatomic levels and are considered completely unpredictable and non-deterministic (stochastic).
These methods generate random "noise" signals, such as thermal noise, the photoelectric effect, and other quantum phenomena whose signatures are theoretically and random.
TRNG is used in various domains, such as cryptography, statistical sampling, simulation methods, experimental physics, etc.
The other category of RNG is the pseudorandom number generators (PRNG).
Keep in mind
RNG generates sequences of random numbers, where the 'random' quality of the generated sequence assumes it meets two requirements – independence and uniformity.
PRNG is a software algorithm for generating a sequence of numbers whose properties meet the requirements of independence and uniformity as much as possible.
The PRNG works by inputting an initial value, called the 'seed,' into the algorithm. The algorithm generates a number through its formulas in which the seed is the value of a variable.
The subsequent numbers are generated as a function of the previous number or numbers, according to the specific math formulas involved.
Of course, the algorithm does the main job, whose mathematics can fulfill the roles of random generation.
Remember
The PRNG-generated sequence is not theoretically (truly) random because the seed determines it. As such, it approximates the properties of a sequence of random numbers; this is why the prefix "pseudo" is present in the RNG name.
Hence the PRNG does not produce "pure" randomness, per the abstract description of the concept, but "sufficiently applicative" randomness (hence the prefix 'pseudo').
Indeed, the existence of a seed and an algorithm that assumes either recursive formulas or functions applied to the seed theoretically undermine the independence requirement.
However, the properly chosen mathematical construction and structure of the algorithm, together with other features of the computer program that the algorithm is embedded in, make this theoretical objection irrelevant with respect to application, utility, and effectiveness.
As for uniformity, this is a strength for the PRNG algorithms, whose mathematical formulas ensure this requirement unquestionably.
Keep in mind
Pseudorandom generators do not provide randomness in their pure form (which is not yet definable) but in an acceptable form relative to the specificity of the application.
Pseudorandom number generators are suitable for and used in domains where the speed in number generation and reproducibility are essential. The gambling industry is one of such domains, but there are others, such as cryptography, machine learning, computing, mathematics problem-solving, and simulations.
The speed and reproducibility of software using a PRNG algorithm account for the quality of the produced randomness itself. Indeed, the software can run continuously to generate outputs in the order of hundreds or even thousands per second.
When a 'spin' button is pushed in a virtual casino game such as roulette or slots, the PRNG outputs only one number of those thousands or tens of thousands generated between two pushes.
Hence the consecutive outcomes of a casino game are not one-to-one associated with the successive outputs of the PRNG.
This feature should make us waive any concern about independence, but it is more than that: the seed numbers can be generated as well as outputs and inputted back as random seeds.
Such functionality features remove any concern about a PRNG's major weaknesses or biases as long as we know that someone qualified has checked it against them. We will talk about this in a future section.
There are several categories of PRNGs. The most known category associated with the early works on PRNG in the 1950s is that of PRNGs based on linear recurrences.
The standard class of PRNGs based on linear recurrences is the linear congruential RNG. This PRNG was conceived in 1958, as a generalization of an earlier work in 1951 (called the Lehmer generator).
It was the most influential and studied generator and is still used in various domains, including gambling. There were multiple objections to this generator regarding its weaknesses, which have undergone improvements over time. Although nowadays PRNGs are much more advanced, the linear congruential RNG is an excellent example based on which one can understand how a PRNG works.
Let's start with the working algorithm, which consists of a recurrence relation between two successively generated terms. It looks like this:
Of course, for every value of these three parameters, a new particular algorithm is obtained, so what we have above is a class of linear congruential algorithms.
Specific values for the parameters are chosen to provide an algorithm suitable for every particular application of random number generation.
Let's see now what the roles of these three parameters are.
First, what was the rationale for involving the modulo operation in the formula of the algorithm?
If you take a sequence of consecutive integers and choose a divisor for them, you will see that the reminders form a periodical sequence of consecutive numbers, where the terms repeat with the period given by the divisor.
The last row shows the reminders at the division by 5, which are only five in number. We see that these reminders show periodically in consecutive order.
The sequence in the last row is uniform – no value has two or more instances in a row, and the values are evenly distributed over the sequence (two identical values are placed at the same distance from each other).
Uniformity is what we expect from a random sequence, and periodicity provides a kind of uniformity. Periodicity is the reason for choosing the modulo operation for the algorithm. It also has a practical sense – in most applications, the random generation must provide numbers in a given set or range, whatever the seed. This also applies to casino games, where the individual outcomes are finite – we need the PRNG algorithm to generate only 37 or 38 numbers for roulette, 52 or 104 or more numbers for card games, and specific numbers associated with the stops of each reel in slots.
However, the sequence in the example above is just "too" uniform or perfectly uniform, and we don't want such a predictable order in a randomly generated sequence of numbers. Recall that randomness should be both order and disorder.
The sequence in our example is generated by the linear congruential algorithm, a particular instance of the general algorithm, where a = 1 and c = 1, with seed. Obviously, we won't accept such a PRNG algorithm, as each of its outputs is predictable. Let's increase the increment c by 1 and run now with seed 4. We get the sequence:
4, 1, 3, 0, 2, 4, 1, 3, 0, 2, 4, 1, 3, 0, 2, 4, 1, …
What changed? Of course, we have the same period of five numbers, but the reminders are no longer in consecutive order; they look "shuffled," and this is what we want. This was the role of parameter c – to remove the consecutive order.
Still, this new sequence is unacceptable, as the numbers are arranged identically within each period. This issue can only be overcome if the modulo operation is in force, but choosing big numbers for parameter m makes it neglectable in practice. Popular values for m are or, which are huge prime numbers providing huge periods for the outputs. A technique for breaking the correspondence between periods is to input arbitrary seeds at several moments of the generation.
Another concern is that we expect to see all possible reminders of m, even "shuffled" within a period. This can be changed by changing multiplier a. Choosing may provide a period with a length less than m, where some reminders are missing. For example, in which a = 3, with seed 4 gives the sequence:
4, 1, 0, 2, 3, 1, 0, 2, 3, 1, 0, …, with a period of length 4, where reminder 4 is missing starting with the second term. For huge values of m, such missing is not even detectable. Besides reducing period, the multiplier also has a role in "shuffling" concerning the differences between two consecutive outputs. For the same increment, the higher the multiplier, the more randomly distributed the outputs.
The choice of parameters (m, a, c) is decisive for the outputs to look random; every application requires specific choices.
For the linear congruential RNG, the (pseudo)randomness effects on the outputs are a direct consequence of the mathematical construction and properties of the working algorithm. The outputs behave according to some specific properties provided by number theory.
Another kind of algorithm may use different mathematical constructions, belonging to other mathematical theories. Still, many combine linear congruential components with components of other mathematical nature (ergodic theory, polynomial fields, Cantor spaces, etc.)
Keep in mind
The linear congruential random number generator is based on an algorithm using the modulo operation applied to a first-degree linear expression. The modulo operation provides periodicity, and the linear expression provides uniformity.
In general, the requirements for a random sequence are fulfilled by the mathematical properties of expressions of the working algorithm.
For the electronic versions of the classical games of chance, using PRNGs is necessary, as the outcomes of such games cannot be generated randomly by other means.
The PRNG is embedded in the software of each such game, whether we talk about games played in online casinos or electronic games played in brick-and-mortar casinos. Even some versions of electromechanical slots use PRNG for the outcomes of their spins.
Some games of chance – usually not played in classical casinos – such as lottery or bingo, use physical shuffling devices as a rudimentary (but accepted) form of TRNG.
The scheme of functioning for the games with PRNG is straightforward:
The "stops" for the individual outcomes of the game (pockets on the roulette wheel, stops of the slots reels, and so on) are given numbers (in one-to-one correspondence), which are then associated with the commands that produce the displaying of each outcome.
That number associates the output of the PRNG with a command displaying the respective stop with its outcome.
In electronic roulette (or physical roulette with electronic croupier-free spin), there are 37 stops for European or French roulette and 38 stops for American roulette. A PRNG will have to generate numbers from 1 to 37 or 38, each associated with a pocket on the roulette wheel. A linear congruential RNG with parameters m = 37 (or 38) and a = 1 would work for that task. Check out the complete roulette odds analysis to learn more about the maths behind the roulette game.
In electronic blackjack or baccarat, cards are "shuffled" and "dealt" by the PRNG. Each card in a deck is associated with a numerical value.
The PRNG is set initially to output 52, 104, 156, or more values (depending on the number of decks used in the game) and reset after each output to remove the values corresponding to the cards that were already dealt.
Periodical-output PRNGs (such as linear congruential RNG) work for that task.
The same principle of using the PRNG applies to video poker, where jokers are also counted with numerical values.
In electronic craps, the possible outcomes at each dice roll are all ordered 2-size combinations of numbers from 1 to 6, namely (1, 1), (1, 2), (1, 3,), …, (1, 6), (2, 1), (2, 2), (2, 3), …., (6,6), counting 36.
The PRNG must randomly generate numbers from 1 to 36 at every die roll, each associated with a combination from the previous list.
Keep in mind
In casino games, the PRNG works by associating each game stop, which carries an outcome, with a number following to be randomly generated.
In the game of slots with virtual reels and some electromechanical slots, the PRNG generally works as described for the other casino games. The only difference is that random number generation is required for each reel separately since the reels' outcomes should be independent.
Hence a PRNG works for each reel and is set to output random numbers from 1 to the number of stops on that reel (usually 22 for electromechanical slots or 64, 128, or 256 for virtual-reel slots).
For the old mechanical slots, the mechanism that spins the reel acts as a TRNG. Such mechanisms provide enough high-speed rotation and frequency to accept their outcomes as random. However, no one can say with certainty that a specific machine is random unless statistical analysis based on recording thousands of spins is done.
Keep in mind
In slots, the PRNG picks the outcome for each reel separately.
With the evolution of slots, more and more symbols have been added to the reels. However, the physical reels of mechanical and electromechanical slots cannot hold more than a limited number of stops (usually 22).
For virtual-reel slots, the PRNG picks a number for each reel directly to command the stop that the reel will display after "the spin ." So the overall outcome of the machine will be a combination of symbols associated with the combination of stops picked by the PRNG on each reel.
Modern electromechanical slots have "invisible" virtual reels with far more stops than physical reels.
There is a reduced weighting of the symbols on the physical reel such that the reel displays as many symbols as possible while making the actual weighting on the virtual reel.
By the inner design of the machine, the virtual reel is mapped onto the physical reel: Several stops with the same symbol on the virtual reel are mapped into one stop on the physical reel.
The generating of the outcomes by PRNG also works through mapping: Each stop on a virtual reel is given a number.
The PRNG generates a number for each virtual reel, mapped onto a stop on the associated physical reel, per the machine's design.
Then the machine commands the physical reels to stop on the spots selected indirectly through the PRNG.
As such, the PRNG does not pick symbols but stops (spots holding symbols). A blank on a reel is a symbol, and when the machine displays a blank, the PRNG picks a specific blank (that is, the particular spot holding that blank).
The mapping between virtual and physical reels may create a statistical illusion for the player: If you know, guess, or observe what the symbol distribution and weighting on the physical reel are, you may estimate the chances for a symbol to show at a spin by doing the ratio between the number of spots holding that symbol on the visible reel and the total number of stops of the reel.
However, this computation should be done on the invisible virtual reel, as the stops of the physical reel are no longer equally probable.
Be aware
In electromechanical slots, the stops on the physical reel are not equally probable; they are mapped from the virtual reel. The PRNG picks stops on the virtual reel and not symbols on either reel.
This is not the only illusion that the design of slots may induce in players. There are also cognitive illusions, some indirectly connected to the PRNG behind the machine.
In slots with virtual reels, the spin of the reels is illusory, and we all know that.
However, for the modern electromechanical slots, even though the spin is physical and tangible, its outcome is not in real-time.
By the time the reels are spinning, the game is already over, just because the PRNG has already selected the stops for the outcome; the reels spin as a kind of courtesy to the player (but also for maintaining that illusion).
Another cognitive illusion is that of control: many games have a hold button, which, when pressed, stops the apparent spin of the virtual reels. However, the outcome is determined by the PRNG and not by any physical effect of that button on an illusory motion.
The PRNG is working continuously, even when you're not playing, picking hundreds or thousands of numbers per second (and this happens in all electronic casino games).
When you press the spin or stop button or pull the lever, the PRNG picks several numbers to generate the outcome.
So if someone hits the jackpot on a machine you were just playing, you shouldn't feel frustrated, as you would have hit the spin button at a slightly different time than they did.
Keep in mind
In slots, the PRNG generates numbers in the order of hundreds or thousands per second, and only one of them determines the outcome. This means that:
1. The outcome is determined before being displayed when the spin stops.
2. The outcome cannot be associated with any physical command of the player.
Another illusion in slots is the near-miss effect, a gambling-specific cognitive distortion. This effect is caused by the mathematical design of the game, and the PRNG is not responsible for that.
The design may be manipulated by choosing specific weightings for the symbols on the reels (through techniques such as award symbol ratio or clustering).
As a result, some combinations looking like near-misses will frequently occur, creating a false impression to the players that they were close to a win.
Although the PRNG is subject to test and certification by the gambling authority, the mathematical design allowing artificial near-misses is not.
Be aware
Most of the so-called "near-misses" are artificially created by the mathematical design of the game of slots. This means that you were not "close to a win" when one occurred, but it was just a non-winning outcome as any other. Learn more about slot odds in my complete guide.
The RNG is a crucial software component of a casino game since randomness and fairness rely on it.
This is why almost every jurisdiction has legal regulations that establish the obligation of every casino to have their software tested and audited by an independent expert third party. These experts or expert organizations (consisting of mathematicians, statisticians, or programmers) offer a full range of testing and consulting to game developers and casinos.
This includes:
The RNGs that pass such tests and evaluations are certified as fair, which means they are sufficiently random and adequately implemented into the game's software.
The independent audits ensure that the outcomes of the games are not influenced by variables such as the number of credits in play, the size of the potential payout, VIP cards, and other subjective factors.
Changes cannot be made to a particular game or machine by a producer or casino without an extensive process that must follow the legal regulations: notifying the state gambling authority and then having inspectors randomly check the machine for compliance, especially in what concerns RNG.
When a gambling site is certified as fair, its games comply with all regulations, and its RNGs are fairly random. Players can check this by looking for the certification seal on that website.
But what tests are in force for evaluating the RNGs and deciding which are good and which are not, per the legal standards?
These tests are of two main categories: empirical tests and theoretical tests. Empirical tests are applied on a sequence generated by the tested RNG, requiring no information on how the RNG produces the sequence. Theoretical tests are apriori tests in the sense that they require knowing the algorithmic structure of the RNG, but any sequence does not necessarily need to be generated.
The empirical tests check whether specific statistical criteria are met, like:
The theoretical tests try to derive behavioral properties of the sequence from being generated directly from the RNG algorithm.
These theoretical tests are specific to each class of generators and include the lattice and spectral tests. Discrepancy bounds calculations, period length calculations, etc.
Empirical and theoretical tests are used in the scientific audit of an RNG; a standard recipe for applying them does not exist.
The testing methods are variable and are left to the competence of the experts.
The methods are also specific to each class of RNG and its domain of use – for instance, tests for RNG in gambling are different and have different targets than tests in cryptography.
Keep in mind
Any operator or casino must have their RNGs tested for fairness and randomness by an independent expert third party for working in legality. Legal gambling websites offering the games have a certification seal acknowledging that their RNGs passed those tests.
First, what would it mean for an RNG to be cheated? The answer can be formulated from two perspectives – from the operator's and the gambler's.
For the operator, cheating with the RNG would mean that it is not fair and is set to generate outcomes that are either frequently favorable for the house or for players who bet or play with specific wagers or have special statuses.
Of course, such an RNG would not pass the randomness tests so we can assume that any operator or casino that runs it does that out of the law.
So the fair question arises as to whether such illegal activity is worth running since the casino is ensured a decent profit over the long run in normal conditions of randomness and legality.
Hence the first answer would be: Yes, a casino can cheat with its RNG, but it is not worth it.
For the gambler, cheating or beating the RNG of a game means knowing it and using that information to predict its outcomes.
While the former condition (knowing it) means having access to the inner design and code of that game and, as such, can be granted 'possible' (but you need espionage skills for that), the latter (using it) is non-sense:
Good RNGs will provide sufficiently random outcomes for you to guess them while knowing their algorithms. If seeds are generated randomly or are unknown, understanding the algorithms would not make the outcomes predictable.
Moreover, the RNG is usually run several times in a second, so you won't know which outcome is generated with a particular seed. The only exception (though unrealistic) for this argument is when you are cheating RNG with the house or the operator.
So we can fairly answer no to the initial question from the gambler's perspective.
Keep in mind
In practice, the RNG cannot be cheated or beaten by either operators or gamblers.
Random number generators (RNG) are an essential and necessary software component for modern electronic casino games.
They are the only technology available for ensuring an acceptable randomness for the outcomes of such games, meaning that any long sequence of outcomes meets 2 main criteria:
Pseudorandom generators (PRNG) are software algorithms incorporated in the machine's software, which works by inputting a seed and random numbers in a given range or set.
Various kinds of PRNGs produce weaker or stronger randomness. The random behavior of their outcomes is the direct result of the mathematical properties of the working algorithms.
In casino games, the PRNG works by associating the generated numbers with the possible stops/spots or outcomes of the game: Once a number is picked, the machine will command that associated outcome to be displayed.
Given their importance in ensuring the fairness of a game, the RNGs are subject to legal regulations, which include tests and evaluations before being incorporated into a casino game.
Such tests are based on statistical criteria and mathematical methods and are performed by independent experts.
The RNGs cannot be cheated or beaten by either operators or gamblers, except in highly improbable fraudulent conditions.
If such possibility existed on a large scale, games of chance would not be what they are – games in which the luck factor is constitutive, decisive, and fair by its random nature for all parties involved. Check the Online Gambling Academy and learn more about casino games and how they work.
I'm looking for a slot machine from 20 years ago, four reels and stars, the stars palette was a bonus. Does anyone remember such a slot machine?
Hi guys, what is the best reccomended bank to use in South Africa for making deposits.
Just here to make it aware that you could loose everything chasing after more than you really need ,i salute chipy for giving individuals a platform to express themselves and ask questions.