# How do online casino games work?

Posted by THEPOGG in Blog.In this article we will attempt to provide an explanation of exactly how online casino games function. In each section the we will attempt to provide a short answer and an expanded explanation and these explanations will be added to and expanded as and when appropriate information comes to light.

Most of this article was authored by our resident casino software expert Binary 128 (you can chat to him on the message boards). Binary 128 is one of the developers behind GaleWind Software, the casino platform for Pinnacle sportsbook.

**INDEX**

- What is a Random Number Generator (RNG) and how does it work?
- What does this mean?
- How does a Random Number Generator guarantee that any number in a requested range has exactly the same chance of being returned as any other number?
- Does a fair RNG assure me that Iâ€™m getting a fair game?
- What purpose does RNG testing serve?

__What is a Random Number Generator (RNG) and how does it work?__

In an online casino a Random Number Generator (RNG) is something that returns a number to whatever asks it for a number. It’s as simple as that.

Let’s use European Roulette (single Zero) as an example. The “wheel” spins, and needs to stop on a number between zero and 36. So, the “wheel” asks the RNG for a number between zero and 36. The RNG returns 17.

The RNG doesn’t know or care what is asking for that number. The ONLY thing that it does – when something asks it for a number within a range, then it makes sure that __any number in that range__ has **exactly** the same chance of being returned as __any other number__.

- When a European Roulette “wheel” asks it for a number between zero and 36, then zero has
**exactly**the same chance of being returned as 1, or 17, or 36. - When a Video Poker “dealer” asks it for a number between 1 and 52, then 1 has
**exactly**the same chance of being returned as 2, or 23, or 52.

And that’s it. The RNG doesn’t know that in one case it is a Roulette “wheel” that is asking, and in another case it is a Video Poker “dealer” that is asking. It doesn’t know what the number is for, or how it is going to be used.

In that way, the RNG is one of the stupidest parts of online casino software. Something asks it for a number, it returns a number, and its job is done (until something else asks it for another number).

Again, the ONLY thing that an RNG does – when something asks it for a number within a range, then it makes sure that __any number in that range__ has **exactly** the same chance of being returned as __any other number__.

__What does this mean?__

The most important part of the Quick Answer was the statement – When something asks the RNG for a number within a range, then the RNG makes sure that __any number in that range__ has **exactly** the same chance of being returned as __any other number__.

When the Roulette “wheel” spins, and asks the RNG for a number between zero and 36, the RNG returns 17. When the “wheel” spins again and asks the RNG for another number, 17 has **exactly** the same chance of being returned as __any other number__. And when the “wheel” spins again, then again 17 has exactly the same chance of being returned as __any other number__.

When Players see the number 17 returned three, or four, or five times in a row (or even more), then they start thinking “Hey, this isn’t a random wheel! Is this game rigged!” That’s because people see things in “patterns”. People like to see “patterns” so much that they can see them in things even when there are no real “patterns” there at all. (Let’s call it imagination.)

But, like I said earlier, RNGs are just amazingly stupid. They have absolutely no imagination. AND, they have no memory. They don’t know what the last number they gave was, what the requested range was, who asked for it – nothing – __no imagination, and no memory__.

So, for an RNG, returning the number 17 to a Roulette “wheel” three, or four, or five times in a row is … random. It doesn’t happen very often, and because it doesn’t happen very often the Player notices it even more. If the Roulette “wheel” stops on:

14, 12, 2, 3, 2, 34, 27, 21, 6, 15, 13, 22, 36, 9, 0, 17, 17, 17, 17, 17

Those five 17s in a row stick out like a sore thumb. “Hey, this isn’t random. How can you have a pattern with five 17s in a row?”

There is no doubt – it can be a little confusing to think about it.

But if we look at that sequence of numbers above, then the first five numbers – 14, 12, 2, 3, 2 – have exactly the same chance of being returned as the last five numbers – 17, 17, 17, 17, 17. That is, the __exact return order__ of 14, 12, 2, 3, 2 has **the same chance** of happening as the __exact return order__ of 17, 17, 17, 17, 17.

This last part can be difficult to really understand, but … that is random.

__How does a Random Number Generator guarantee that any number in a requested range has exactly the same chance of being returned as any other number?__

There are two methods to a Random Number Generator (RNG). The first method is the one that generates a random number – I’ll call this method **Generate**. The second method transforms that random number into something that can be used by whatever asked for it – I’ll call this method **Scale**.

__The Generate method__

There are 2 different types of things that can **Generate** a random number – the first is a piece of hardware, and the second is a piece of software. A hardware example is the QUANTIS product from a company named ID Quantique. A software example is named the Mersenne Twister Algorithm.

The VAST majority of online casino programs use a piece of software to **Generate**, and the Mersenne Twister is a very common software program. (Galewind Software uses it.) When I use examples in all of this documentation, I’ll tend to focus on the Mersenne Twister.

The **Generate** method usually returns a number from one of two different **Generate Ranges** (depending on the software). Range #1 is [0 to 0.999999999999999]. Range #2 is [0 to 4,294,967,295]. (The Mersenne Twister uses Range #2.)

The most important contribution of the Generate method to the RNG’s performance – over the millions, or billions (or trillions) of numbers that it is asked to return:

- there is no observable pattern to those numbers (aka Correlation).
- those numbers are equally distributed across the Generate Range (aka Bias).

In other words, the **Generate** method returns a Random Number. No Correlation is the “no one can guess the next number” guarantee. No Bias is the “every number has an equal chance” guarantee.

There are all sorts of tests that can be run on the numbers that the **Generate** method returns to determine their “quality” as “random numbers”. (Link to Test Details 1. Link to Test Details 2.)

(The “quality” of the “random numbers” returned by the Mersenne Twister Algorithm is considered excellent.)

__The Scale method__

Since a large number of online casino software uses the Mersenne Twister to **Generate**, let’s focus on the Mersenne Twister to talk about **Scale**.

As we’ve seen, the Mersenne Twister’s **Generate** method returns a random number in the **Generate Range** of 0 to 4,294,967,295. Obviously, these numbers are of no use to a Roulette “wheel” that is asking for a value between 0 and 36. The **Generate** method’s random number has to be transformed into a number that can be used by the “wheel”. __Most importantly__, it needs to be transformed __without messing up__ the “quality” of the **Generate** method’s “random number”.

Here is one way to make that happen.

The Mersenne Twister’s **Generate Range** (including 0) is 4,294,967,296 numbers. The Roulette “wheel’s” requested range is 37 numbers. Divide 4,294,967,296 by 37, and we get 116,080,197.18919. Throw away the decimal and we get 116,080,197.

Now set up 37 “number bins”, one for each of the Roulette “wheel’s” requested range. The first bin will return to the “wheel” the number 0, the second bin will return the number 1, and so forth. The last bin will return the number 36.

Into each of these “number bins” we put exactly 116,080,197 numbers. The first bin will contain the numbers 0 to 116,080,196. The second bin will contain the numbers 116,080,197 to 232,160,393. The last bin will contain the numbers 4,178,887,092 to 4,294,967,288.

Finally, we ask the Mersenne Twister to **Generate** a random number – it returns 2,031,403,430. (Bin 18, which returns the “wheel” number 17, contains the numbers 1,973,363,349 to 2,089,443,545). So, the **Generate** number 2,031,403,430 returns the **Scale** number 17 to the Roulette “wheel”.

__A Final Note__

You can see that the highest number that the Mersenne Twister’s **Generate** method can return is 4,294,967,295. But the highest number in the last Roulette “wheel” bin is 4,294,967,288. This is a difference of seven numbers.

If the Mersenne Twister’s **Generate** method sends into the **Scale** method one of these seven numbers, then the **Scale**Scale method asks the **Generate** method for another number.

If we were to include these seven numbers in our 37 bins, then:

- either seven bins would have 1 number more than the other thirty bins.
- or one bin (the last bin?) would have 7 numbers more than the other 36 bins.

Neither of these solutions would be acceptable to a “High Quality” RNG. Here, I think, we have an example that people can understand of what a “High Quality” RNG means.

For our Roulette “wheel”, each bin contains **exactly** 116,080,197 numbers. If one of these bins contained __even 1 number more__ than the others – 116,080,198 numbers, a difference of 0.0000009% – this would not be acceptable to a “High Quality” RNG. This would mean that, over billions and billions of spins, this bin’s wheel value would appear once, twice, maybe 3 times more than it should appear.

A difference of __3 times out of 10 billion spins__ **is significant** to a “High Quality” RNG!

__Does a fair RNG assure me that Iâ€™m getting a fair game?__

Not by itself. As stated above all an RNG does is ensure that __any number in that range__ has **exactly** the same chance of being returned as __any other number__.

Letâ€™s give an example of a situation wherein the RNG is fair, but the game is not.

An RNG is set to select a number between 1 and 74 for a European Roulette game and we assign the numbers that the RNG returns the following results on the Roulette wheel.

RNG Number |
1-2 |
3-5 |
6 |
7-9 |
10 |
11-13 |
14 |
15-17 |
18 |
19-21 |
22 |
23-25 |
26 |
27-29 |
30 |
31-33 |
34 |
35-37 |

Roulette Result |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |

RNG Number |
38 |
39-41 |
42 |
43-45 |
46 |
47-49 |
50 |
51-53 |
54 |
55-57 |
58 |
59-61 |
62 |
63-65 |
66 |
67-69 |
70 |
71-73 |
74 |

Roulette Result |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |

Now looking at the above table it should be clear to see that the odd numbers are going to come out 3 times as often as an even number. Clearly in this example, this Roulette wheel isnâ€™t returning fair results (those which youâ€™d expect to receive playing at a real Roulette wheel) despite the fact that the RNG is functioning perfectly. This is a grossly simplified example of how a game could manipulate a correctly functioning RNG to deliver bias results (in fact this particular game could easily be beaten by any player who realised that odd numbers were coming out more than they should), but it illustrates the point well. How the game uses the results that the RNG returns are as important to receiving a fair game as the RNG functioning correctly is.

__What purpose does RNG testing serve?__

The vast majority of casinos will display a seal from one company or another stating that their RNG has been tested and approved as random. They advertise this as if itâ€™s done for the players benefit â€“ in fact this testing has far less to do with protecting the player than the casino.

As shown above, a correctly functioning RNG can still be used to create unfair results for the player. However a RNG that doesnâ€™t function correctly is just as likely to help the player as hurt them. The RNG just returns a number. If it malfunctions and returns one number more often than the others, whether that helps or hurts the player completely depends on the game that requests the number and how it uses the result.

More than this, an RNG that functions at an insufficient level can be used by players to predict what future results will be, which for obvious reasons would put the casino at a substantial disadvantage. This has actually resulted in players winning notable sums in offline Video Poker in at least one instance.

While having a correctly functioning RNG is essential to a casino providing you the normal game you expect to receive, testing RNGâ€™s protect the casino to a far greater degree than any assurance it offers the player.

It should be stressed however RNG testing is a cornerstone of proving that casino games are fair. Without first proving the RNG is functioning any game testing will prove absolutely nothing. RNG testing is the essential first step that is required if a casino are offering fair games.

Tweet