Imagine a die (one of a pair of dice). It has 6 six sides and each side is labeled with a number from 1 to 6. You roll the die and write down the number. You do this over and over and you develop a very long list on numbers. You certainly are generating numbers. And the numbers are always in the range of 1 though 6. If the die is a fair die, you will also be generating random numbers. I hope this gives you an intuitive feel for what a random number generator is.

Let’s say on your first roll, you get a 4. You don’t have enough information yet. You can’t hold 4 up to the light and say it is random or not random. Ramdomness is a property that a list of numbers has. It is not a property that can belong to single number. But this doesn’t mean that you roll the die a second time and have enough numbers. You need a lot. And the more the better. After you roll the die, say, 600 times, you have enough numbers that you could run some statistical tests. One thing you could do is tabulate the numbers up and see how many one’s you got and how many two’s, etc. If you got 400 six’s, that die has probably been tampered with. On the other hand, if you got exactly 100 of each number, that would also be odd. You could take this table and run a test called a Chi Square test to see how reasonable your distribution is. This is the easiest test for a random number generator to pass. So simply passing this test is not enough. But failing it is a disaster, a clear indication on non-randomness. And it’s not even a pass/fail kind of thing. Once I was testing a RNG that I wrote. I ran the test a fe times on 10,000 numbers and passed, but not like I expected. I then ran it a few times with 100.000 numbers and got a worse score, but still passing. At that point, I suspected a bug, and sure enough, I found it. I was generating numbers in the range of 1 to 100, but I was favoring 1 to 10 slightly and the longer I ran the generator, the more obvious the favoring was. (I don’t actually recall the range or which numbers I was favoring, but this is a real experience.)

There are several suites of test for randomness. George Marsaglia wrote a test suite called DieHard which many authorities claim to be the hardest one to pass. There are several other test suites that are easier to pass.

It is not easy for a computer to generate random numbers. Most RNG’s will take a number called a “seed” to start it up. Then it will produce a list of random numbers. At some point though, it will repeat. It is said to have a “period”. So in effect, it is a table of random numbers. When you reach the end of the table, you go back to the beginning. For a long time this was pretty much all we had. And the periods were short. And the list of random numbers was not super random. The algorithms have improved over the years. The periods get longer and longer. And the list passes more and more tests. Mostly because of the periodic nature of these generators, they are called Pseudo Random Number Generators. But the best of them are very good, passing every known test and exhibiting period that take years to exhaust. There are some extremely good algorithms, but they take a very long time to generate a random number. So you want to consider your needs and not just go for the best.

Another approach is a hardware random number generator. Some hardware random number generators are actually very poor, failing many tests for randomness. Despite this, they are often called True Random Number Generators. That Intel chip is very good and it passes DieHard. I knew it was in the chipset, I didn’t know it had been embedded in the cpu, but I guess it was just a matter of time. There is another hardware RNG somewhere that passes DieHard. But most True Random Number Generator do badly when tested… I would not use one without testing it.

You know, I would have bet that a roulette wheel is damn fine random number generator. But I saw a show where some guy watched roulette wheels and saw that they favored some numbers. He won a small fortune before the casinos threw him out. So I guess that I was wrong about roulette wheels. Well I will still bet that dice are damn fine random number generators, but I won’t bet more than a dollar. So maybe my example in the first paragraph isn’t that valid. I don’t really know. Generating random numbers is not as easy as it seems.