Pseudo Random Number Generator Formula Slot Machines

Today, the mathematics of slot machines. The University of Houston mathematics department presents this program about the machines that make our civilization run, and the people whose ingenuity created them.

  1. Random Number Generator
  2. Pseudo Random Number Generator In Slot Machines
  3. Random Number Generator Algorithm
  4. Pseudo Random Number Generator Formula
  5. Pseudo Random Number Generator Formula Slot Machines Required

How the numbers are generated. I wrote a program in Javascript, using the built-in Math.random function. In most web browsers (Chrome, Safari, Firefox) Javascript uses an algorithm called Xorshift128+ to generate pseudo-random numbers. Wired is reportingon a new slot machine hack. A Russian group has reverse-engineered a particular brand of slot machine — from Austrian company Novomatic — and can simulate and predict the pseudo-random number generator. The cell phones from Pechanga, combined with intelligence from investigations in Missouri and Europe, revealed key details.

Mathematicians first got interested in randomness by studying games of chance. Ever since, the histories of mathematics and gambling have been intertwined. Clever gamblers use mathematics to look for the smallest advantages, and casinos use sophisticated mathematical tools to devise new ways of drawing in players.

Indeed, a patent granted to the Norwegian mathematician Inge Telnaes in 1984 transformed the gambling industry. Prior to Telnaes’ invention, slot machines were essentially mechanical devices. Besides being difficult to tune and maintain, mechanical slot machines suffered from an essential problem: Let’s look at a machine with three reels, each with 12 symbols, with one of those 12 symbols a cherry. The likelihood of getting three cherries, and winning the jackpot, is 1 in 1,728. If the casino wants to make money, the jackpot payout should be, say $1,700 on a $1 bet. That does not seem attractive by today’s standards. However, the only way to increase the payout is to decrease the chances of hitting a jackpot.

Adding another reel is a possibility. For instance adding a fourth reel in the previous example would get us to a jackpot of about $20,000. But people do not like machines with more reels — they intuitively, and rightfully, feel that extra reels diminish their chance of winning. Another possibility is to put more symbols on each reel. But the astronomical jackpots you see in casinos today would then require truly enormous machines.

Inge Telnaes proposed a simple solution: Let a random number generator — a computer chip — determine the combination of symbols that appear when the reels stop. In other words, use a chip to control where the reels stop on a spin, but create the illusion that the wheels stopped on their own. The number of possible outcomes on the slot machine does not change. However, by reprogramming the chip, the operator has full control over the likelihood of each of the different outcomes. For instance, the operator could make the three cherries appear only once in a million spins.

This was a brilliant insight: Suppose I pick a number between one and a million. Would you be willing to bet that you can guess that number? The answer is probably not. But let a computer chip pick such a number, put the chip in a machine with blinking lights and spinning reels, and many people will be more than willing to make the bet. It is simply because what people assume is happening in a slot machine is very different from what is actually happening.


The Magician oil painting by Hieronymus Boschfrom between 1475 and 1480

The history of gambling is also intertwined with that of a less reputable group — tricksters and swindlers. In the long run, the only sure way to make money by gambling is to create the illusion that your opponent can win, while keeping the odds firmly on your side. And that gives those who know math a very solid advantage.

I'm Krešimir Josić, at the University of Houston, where we're interested in the way inventive minds work.

(Theme music)

NOTE: In the example with three cherries, I assumed that one only wins in the case the spin results in three cherries, and there is no other winning combination. In actuality, there are typically many winning combination, and as a result, the jackpot would have to be even smaller.

The following story in Wired Magazine shows the drawbacks of the new generation of slot machines — they are easier to hack and to counterfit than their mechanical counterpart http://www.wired.com/magazine/2011/07/ff_scammingslots/.

Here is a more exhaustive discussion of the history of slot machines, and the random number generators within them http://catlin.casinocitytimes.com/article/non-random-randomness-part-1-1243. You may want to scroll towards the end of the article to read about how flaws in the design of gambling machine resulted in somebody picking 19 out of 20 winning numbers in a game of KENO — and doing so 3 times in a row. That person walked away with $620,000, but only after some controversy.

Both images are from Wikipedia. The slot machine image was taken by Jeff Kubina.

For more mathematics in everyday life, visitkjosic.wordpress.com.

This episode was first aired on September 7th, 2011


The Engines of Our Ingenuity is Copyright © 1988-2011 by John H. Lienhard.
Pseudo random number generator formula slot machines printable

Random Number Generator

The Random Number Generator (RNG) is the brains of the slot machine. While most players know that there is a computer chip picking the numbers, they do not fully understand how it works and this can lead to some of the many myths and misconceptions about a slot machine. One of the most common myths is that a machine has a cycle that can let a player know when it is due to hit. Many “Snake Oil Salesmen” will try to sell you a system for doing just that. Save your money — it can’t be done.

The RNG Program

Inside the slot machine is a microprocessor similar to the one in your home computer. Instead of running Word or Excel, it runs a special program, the RNG, that generates numbers to correspond to the symbols on the reel of the slot machine.

You might say that the RNG is in perpetual motion. As long as there is power to the machine it is constantly selecting random numbers every millisecond. The RNG generates a value between 0 and 4 billion (approx number) which is then translated into a specific set of numbers to correspond to the symbols on the reels. The outcome of each spin is determined by the number selected by the RNG. This number is chosen when you hit the spin button or deposit a coin.

The RNG uses a formula known as an algorithm which is a series of instructions for generating the numbers. The scope of this is beyond most of our mathematical knowledge but can be checked for accuracy. This is done by the Casino Control Board and other testing laboratories to make sure that the program performs as it should so the player will not be cheated.

Principles of the Random Number Generator

Here is a more simplified explanation that's easier to relate to. Although this is not precisely how the RNG operates, it should give you a basic understanding of the principles of how the winning spins are determined.

Pseudo Random Number Generator In Slot Machines

Reel Type Slot Machines

Reel type slot machines have a number of spaces on each reel that contain a symbol or blank. These are referred to as the physical stops. Most of the old mechanical machines had reels that could hold 20 symbols while the modern slots have reels with 22 physical stops. The ​microprocessing technology allows the new machines to be able to accommodate a large number of “Virtual stops” which I will explain in a future article.

For this example, let’s simplify things and imagine that there are only 10 stops on each reel. With 10 stops there can be 1,000 different combinations. We get this number by multiplying the number of symbols on each reel. (10 x 10 x 10 = 1,000) The 1,000 combinations that can be attained are known as a cycle, and this is the word that sometimes confuses a player into thinking that the machine has cycles of winning and losing.

The odds of a three number combination being picked are one in a thousand. Theoretically, if you play 1,000 spins you should see each of these number combinations once. However, we all know that this is not the case. If you played a million spins you would see that the numbers would even out to be closer to the actual probability. This is similar to flipping a coin 100 times. Although the odds are 50 -50 you are unlikely to see 50 heads and 50 tails after 100 spins.

The Daily Pick 3 Lottery

Many of you have seen the Daily Pick 3 lottery drawing. They have three glass bowls or drums each containing ten balls numbered 0 -9. The balls are mixed up and when the top is lifted a ball pops up the tube showing you the first number. This is repeated for the second and third number to give you a three-digit winning combination.

Random Number Generator Algorithm

To use this as an example of the operation of the slot machine, we will replace the numbers 0-9 on the balls with slot symbols. In each bowl, we will have one ball with the jackpot symbol on it. Two balls with a Bar, three balls with a cherry and four balls which are blank. Imagine the RNG in the slot machine as the person drawing the winning combination.

Here is the breakdown of the number of times out of a thousand that the winning combination made.

  • 3 Jackpot 1 (1x1x1)
  • 3 Bars 8 (2x2x2)
  • 3 Cherries 27 (3x3x3)
  • Total Wins 37

Pseudo Random Number Generator Formula

The 963 losing combinations consist of:

  • 3 blanks
  • 2 blanks and a symbol
  • 1 blank and two different symbols
  • 3 mixed symbols

Pseudo Random Number Generator Formula Slot Machines Required

The RNG picks these combinations of numbers thousands of times each second. Now imagine a string of blinking lights where only one bulb can be lit at a time. The electrical current is zipping from bulb to bulb down the string. When you push a button the current stops moving and the bulb in that position lights up. In this example, the light represents the three digit number just picked by the RNG. If you hesitated a second before pushing the button the results would be different. This is the same as you getting up from a machine and seeing someone else sit down and hit the jackpot. The chances are astronomical that you would have hit the spin button at the exact same millisecond.