Finding a reliable source of random numbers is essential to making any Monte Carlo simulation work. A good random-number generator pro-duces sequences of bits that are indistinguishable from random coin flips.
This is much easiersaid than done. Generating random numbers is one of the most subtle and interesting problems in computer science because seemingly reasonable solutions can have disastrous consequences.
Bad random number generators can easily cause Monte Carlo simula-tions to give meaningless results. For example, suppose we tried a random-numbergeneratorthat simply alternated heads and tails each time it was asked foranothercoin flip. This generatorwould produce a sequence of coin flips having some of the properties of a truly random sequence. For example, the expected numberof heads aftern random coin flips is n/2, and that is exactly how many will be produced by our simple generator.
But compare the following sequence of 50 real random flips (I used real pennies) with this “phony random” sequence:
real random HTHHH TTHHH TTTHT THHHT HTTHH
HTHHT THHTH THHTT HTHHT TTTHT
phony random HTHTH THTHT HTHTH THTHT HTHTH
THTHT HTHTH THTHT HTHTH THTHT
There are significant differences between the two sequences. First, the real random sequence has an unbalanced number of heads and tails (27 heads versus 23 tails). This is not surprising. In fact, 50 coin flips should end up as exactly 25 heads and 25 tails only 11.2% of the time. Likewise, in the real random sequence there is a run of four consecutive tails. A sufficiently long sequence of flips should have substantial runs of consec-utive heads ortails if it is truly random. Such counterintuitive behavior helps explain why people are lousy at designing truly random-looking se-quences. Many embezzlers, ballot stuffers, and quack scientists have been caught because theirdata oraudit trails were too “random” to hold up to careful scrutiny.
Let’s think through the consequences of using the phony-random gen-eratorwith oursimulation instead of a truly random generator. No mat-terhow many games we simulated, only two different trifecta outcomes would everbe produced! Suppose that wheneverthe first coin was heads, we assigned player1 to be the winnerof the first point (against player2).
Wheneverplayer1 wins the first point, this means that the next “random”
coin flip will always yield a tail, and thus the winnerof the second point will always be predestined. In either case, the outcome of the first coin flip always decides the winnerof the match, and thus the results of our simulation are completely meaningless!
How, then, do we generate truly random numbers on a computer? The short answer is that we can’t. Computers are deterministic machines that always do exactly what that they are programmed to do. In general, this is a good thing, forit explains why we trust computers to balance our checkbook correctly. But this characteristic eliminates the possibility of looking to computers as a source of true randomness.
The best we can hope forare pseudorandom numbers, a stream of numbers that appear as if they had been generated randomly. This is a dicey situation. John von Neumann, the brilliant mathematician who is credited with designing the first modern computer, said it best: “Anyone who considers arithmetical methods of producing random digits is, of course, in a state of sin.”
The pseudorandom-number generation algorithm of choice generates random numbers based on the same principle that roulette wheels use. In a roulette wheel, we start by rolling a ball around and around and around the outeredge of the wheel. Afterseveral seconds of motion, the ball loses enough energy that it drops into the bottom part of the wheel and then
How roulette wheels generate random numbers.
comes to rest in one of the 38 equal-sized, labeled compartments at the bottom of the wheel.
Why do casinos and theirpatrons trust that roulette wheels generate random numbers? Why can’t the fellow in charge of rolling the ball learn to throw it so it always lands in the double-zero slot? The reason is that the ball always travels a very long path around the edge of the wheel before falling, but the final slot depends upon the exact length of the entire path.
Even a very slight difference in initial ball speed means the ball will land in a completely different slot.
So how can we exploit this idea to generate pseudorandom numbers? A big number (corresponding to the circumference of the wheel) times a big number(the numberof trips made around the wheel before the ball comes to rest) yields a very big number (the total distance that the ball travels).
Adding this distance to the starting point (the release point of the ball) determines exactly where the ball will end up. Taking the remainder of this total with respect to the wheel circumference determines the final position of the ball by subtracting all the loops made around the wheel by the ball.
This is the idea behind the linear congruential generator. It is fast and simple and (if set with the right constants a, c, m, and R0) gives reasonable pseudorandom numbers. The nth random number Rnis a function of the (n− 1)st random number:
Rn= (aRn−1+ c) mod m
To complete this analogy, the previous random number Rn−1corresponds to the starting point of the ball, and a and c dictate how hard the ball will
be thrown. Finally, m stands forthe circumference of the wheel. The mod function is just a fancy term for the remainder.
Lurking within my simulation is a linearcongruential generatorwith carefully chosen constants that have been shown to produce reasonable-looking pseudorandom numbers.2The high correlation between the dis-tribution of observed trifectas and our simulation results gives us faith in both ourmodel and ourrandom-numbergenerator.