# Random Numbers for Dummies...(me, please)

**URL:** https://boards.straightdope.com/t/random-numbers-for-dummies-me-please/311765
**Category:** Factual Questions
**Created:** [July 9, 2005, 4:59pm UTC](https://boards.straightdope.com/t/random-numbers-for-dummies-me-please/311765 "2005-07-09T16:59:59Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Stoid](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/stoid/32/272_2.png) [@Stoid](https://boards.straightdope.com/u/Stoid)
#### Post date: [July 9, 2005, 4:59pm UTC](https://boards.straightdope.com/t/random-numbers-for-dummies-me-please/311765/1 "2005-07-09T16:59:59Z")

</div>

I am a math moron. Really, my brain just can’t handle it.

Knowing this, could someone explain something to me…

I play online poker, which uses “random number generators” to deal the cards.

I have heard it said that computers are not truly capable of generating random numbers.

Why would this be true, or someonethink it true? How does one define random numbers and determine whether they are truly random or not?

Can anyone explain this to me like I’m about 7?

---

<div class="post-metadata">

### Author: ![Electronic\_Chaos](https://avatars.discourse-cdn.com/v4/letter/e/bbe5ce/32.png) [@Electronic\_Chaos](https://boards.straightdope.com/u/Electronic_Chaos)
#### Post date: [July 9, 2005, 5:15pm UTC](https://boards.straightdope.com/t/random-numbers-for-dummies-me-please/311765/2 "2005-07-09T17:15:15Z")

</div>

While it’s true that computers can’t generate truly random numbers, you can create the illusion of random numbers, which is almost just as good. The computer has built within it (somewhere, I’m not exactly sure where) a list of “random numbers”, which is called by the program. Then you have to tell the program where in the list of the random numbers you want to start. The best advice I’ve seen for telling where to start is by using the milliseconds of the computer’s time. Again, not exactly sure how this is done, but the logic is that since you’re likely not going to be running on the same exact millisecond every time it’s called, it’s mostly “random.”

---

<div class="post-metadata">

### Author: ![Crowbar\_of\_Irony\_3](https://avatars.discourse-cdn.com/v4/letter/c/f08c70/32.png) [@Crowbar\_of\_Irony\_3](https://boards.straightdope.com/u/Crowbar_of_Irony_3)
#### Post date: [July 9, 2005, 5:19pm UTC](https://boards.straightdope.com/t/random-numbers-for-dummies-me-please/311765/3 "2005-07-09T17:19:36Z")

</div>

Computer generate random numbers which are called psuedo-random numbers. A computer cannot generate pure random numbers as they need instructions as to what numbers to generate, like a pair of dice, because computers are expected to be a consistent system. You input this set of value, you get another set of value.

Hence, to generate random numbers you give the computer a formula which produces the random number. The catch is, if the formula is the same, you will keep getting the same set of numbers over and over again.

What most game programmers do is to ‘seed’ the random number generator. It’s like changing a part of the random number formula so you get another sequence. This is also why it is possible for FreeCells or Soltiare to generate a same game over and over again as long as you know the ‘seed’. Most games and applications which need random numbers usually do it automatically, using the current date and time as the ‘seed’, so you get vastly different results.

For example, on the PS2, some enterprising players have found way to keep duplicating item drops and good game events by changing the console’s date and time to a certain value.

---

<div class="post-metadata">

### Author: ![Electronic\_Chaos](https://avatars.discourse-cdn.com/v4/letter/e/bbe5ce/32.png) [@Electronic\_Chaos](https://boards.straightdope.com/u/Electronic_Chaos)
#### Post date: [July 9, 2005, 5:20pm UTC](https://boards.straightdope.com/t/random-numbers-for-dummies-me-please/311765/4 "2005-07-09T17:20:57Z")

</div>

Oh, here’s something else which may be more helpful. It’s from the book **Game Programming for Teens** published by Premier Press.

> [@](#):
>
> Finding a true random number using a computer is almost impossible. Computers only take input, process it, and produce output – they are not built to produce random numbers, for the most part. Therefore, computers can only produce pseudo-random numbers. For example, if you print out ten-million random numbers, you shouldn’t be able to detect any patterns, and there should be an equal distribution between the numbers. However if you try this on a computer, you will see patterns and you will see slight unevenness in the numbers, but for our purpose, the pseudo-random numbers are close enough to random!

---

<div class="post-metadata">

### Author: ![Futile\_Gesture](https://avatars.discourse-cdn.com/v4/letter/f/f05b48/32.png) [@Futile\_Gesture](https://boards.straightdope.com/u/Futile_Gesture)
#### Post date: [July 9, 2005, 5:36pm UTC](https://boards.straightdope.com/t/random-numbers-for-dummies-me-please/311765/5 "2005-07-09T17:36:57Z")

</div>

The only truly random part of any computer program (if we ignore computers that do have random sources, and that excludes your PC) is the user. The user takes a random amount of time to respond to things and they run the program at random times. So the computer can use these elements as a ‘seed’ to generate numbers that appear random. But the fact is that if the user was to start the process from scratch at the same time, with the same response time, they would get exactly the same numbers. So they’re not really random.

Now if we were to delve deeper, you could argue that the user isn’t random either. They are responding to events and stimuli that dictate what they do, and if we were to repeat these exactly they would result in the same parameters generating the ‘seed’, which would end in the same numbers. Following this argument; nothing that we ever do is truly random and computers are no exception, they just make it a whole lot more obvious.

But, of course, the number of variables that influence the user are in the millions (if not billions), and the very act of attempting to repeat them would change them, so repeating them is impossible. But that’s more of a Great Debate 🙂

---

<div class="post-metadata">

### Author: ![Shalmanese](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@Shalmanese](https://boards.straightdope.com/u/Shalmanese)
#### Post date: [July 9, 2005, 7:59pm UTC](https://boards.straightdope.com/t/random-numbers-for-dummies-me-please/311765/6 "2005-07-09T19:59:45Z")

</div>

Modern computer systems DO have a source of pure random numbers embedded in them. The Via C3 family of CPU’s have a true RNG embedded into the CPU and Intel based chipsets since the i810 have had a RNG onboard. However, not many developers are aware of such features and the results are not cross-platform compatible so uptake has been very minimal.

---

<div class="post-metadata">

### Author: ![Shalmanese](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@Shalmanese](https://boards.straightdope.com/u/Shalmanese)
#### Post date: [July 9, 2005, 8:08pm UTC](https://boards.straightdope.com/t/random-numbers-for-dummies-me-please/311765/7 "2005-07-09T20:08:35Z")

</div>

Oops, that should be: _some_ modern computer systems…

---

<div class="post-metadata">

### Author: ![Thudlow\_Boink](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/thudlow_boink/32/320_2.png) [@Thudlow\_Boink](https://boards.straightdope.com/u/Thudlow_Boink)
#### Post date: [July 9, 2005, 11:33pm UTC](https://boards.straightdope.com/t/random-numbers-for-dummies-me-please/311765/8 "2005-07-09T23:33:38Z")

</div>

> [@Electronic Chaos](#):
>
> The computer has built within it (somewhere, I’m not exactly sure where) a list of “random numbers”, which is called by the program. Then you have to tell the program where in the list of the random numbers you want to start.

On some if not all computers, what’s built in isn’t the list itself but a formula that will generate such a list. Give the formula one number (either the last number it spit out, or, if it hasn’t been used yet, the number of milliseconds the computer’s been on or something unpredictable like that), and it will use it to generate the next number on the “list.”

---

<div class="post-metadata">

### Author: ![ultrafilter](https://avatars.discourse-cdn.com/v4/letter/u/3d9bf3/32.png) [@ultrafilter](https://boards.straightdope.com/u/ultrafilter)
#### Post date: [July 9, 2005, 11:50pm UTC](https://boards.straightdope.com/t/random-numbers-for-dummies-me-please/311765/9 "2005-07-09T23:50:59Z")

</div>

The question is really what it means for a sequence of numbers to be random. According to Bruce Schneier’s _Applied Cryptography_, there are three notions of randomness when it comes to computer output:

1. Pseudorandomness. Sequences are said to have the property if all possible outputs show up with very nearly the same frequency in a sufficiently long sequence.

2. Cryptographically-secure pseudorandomness. These sequences are hard to predict. With the limitations of real systems that others have described very well, it’s possible to predict the next outputs of such a sequence if you have enough previous outputs, but there are techniques for making it so you need a lot of output before you can make reasonable predictions.

3. True randomness. A true random sequence generator would produce two different outputs if given the same input twice. This is what can’t be done by a computer without specialized hardware.

In general, when you hear about a random number generator, it’s meant in sense 1.

---

<div class="post-metadata">

### Author: ![Perderabo](https://avatars.discourse-cdn.com/v4/letter/p/a183cd/32.png) [@Perderabo](https://boards.straightdope.com/u/Perderabo)
#### Post date: [July 10, 2005, 12:34am UTC](https://boards.straightdope.com/t/random-numbers-for-dummies-me-please/311765/10 "2005-07-10T00:34:57Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Perderabo](https://avatars.discourse-cdn.com/v4/letter/p/a183cd/32.png) [@Perderabo](https://boards.straightdope.com/u/Perderabo)
#### Post date: [July 10, 2005, 4:06pm UTC](https://boards.straightdope.com/t/random-numbers-for-dummies-me-please/311765/11 "2005-07-10T16:06:26Z")

</div>

Not to beat a dead horse, but here is a quote from George Marsaglia himself. It explains one of his advanced tests for randomness. The math gets a bit deep in places for a 7 year old, but I think that everyone can grasp what the test is showing and how a weakness of a RNG that seemingly looks very good is exposed by the test.

From _Computers & Applications_, **9** , 1-10, 1993:

> [@George Marsaglia](#):
>
> Start with an idea that provides a very inefficient test, but one that some random number generators (RNG’s) fail. Our monkey (RNG) has a typewriter with 26 uppercase letters A,B,…Z that he strikes at random. (Assume our RNG monkey produces uniform real in [0,1], say by means of a procedure UNI(). The integer part of 26.\*UNI() provides the random keystroke.) Now the CAT test: how many keys must the monkey strike until he spells CAT?
> 
> There are 26[sup]3[/sup] = 17, 576 possible 3-letter words, so the average number of keystrokes necessary to produce cat should be around 17,576. and the time to reach CAT should be very close to exponentially distributed. Exact and approximate distributions and more efficient tests are below; for now, let’s try this simple CAT test for a few common RNG’s.
> 
> The congruential monkey, I = 69069 \* I mod 2[sup]32[/sup], converting to a real UNI on [0,1), gets CAT after 13,561 keystrokes, then another after 18,263, then another 14,872 strokes produces the third CAT. Quite satisfactory.
> 
> Now consider the shift-register (Tauseworthe) monkey that produces 31-bit integers by exclusive or’s, left shift 28 and right shift 3. This is the very generator suggested as a replacement for congruential generators after the discovery of their lattice structure. The shift-register monkey never spells CAT, even after two million keystrokes. He can’t get KAT, DOG, GOD, SEX, WOW or ZIG either. But he can get ZAG, and too often — every few thousand keystrokes. Indeed, it turns out that this monkey was only able to get 7,834 of the possible 17,576 3-letter words, (in a string of one million keystrokes) and of course with his limited vocabulary, he gets those words too often.
> 
> Note that the inability to get CAT should not be attributed to the equivalent of broken keys on the typewriter. This monkey still types each of the letters A to Z with the expected frequencies (and thus would pass a standard test for letter frequency). For example 26,00 keystrokes produced 984 C’s, 967 A’s and 1021 T’s, quite satisfactory. Yet continuing the run to 2,600,000 keystrokes failed to produce a single CAT! As silly as it seems, this is a very effective and convincing way to show the unsuitability of certain random number generators.

---

<div class="post-metadata">

### Author: ![RM\_Mentock](https://avatars.discourse-cdn.com/v4/letter/r/e274bd/32.png) [@RM\_Mentock](https://boards.straightdope.com/u/RM_Mentock)
#### Post date: [July 10, 2005, 4:13pm UTC](https://boards.straightdope.com/t/random-numbers-for-dummies-me-please/311765/12 "2005-07-10T16:13:28Z")

</div>

> [@Perderabo](#):
>
> It explains one of his advanced tests for randomness.

_Advanced_ test? 🙂

---

<div class="post-metadata">

### Author: ![TJdude825](https://avatars.discourse-cdn.com/v4/letter/t/dec6dc/32.png) [@TJdude825](https://boards.straightdope.com/u/TJdude825)
#### Post date: [July 10, 2005, 5:50pm UTC](https://boards.straightdope.com/t/random-numbers-for-dummies-me-please/311765/13 "2005-07-10T17:50:44Z")

</div>

If I’m not mistaken, things like [this](http://www.lavarnd.org/what/how-it-works.html) are truly random.

---

<div class="post-metadata">

### Author: ![RM\_Mentock](https://avatars.discourse-cdn.com/v4/letter/r/e274bd/32.png) [@RM\_Mentock](https://boards.straightdope.com/u/RM_Mentock)
#### Post date: [July 10, 2005, 5:59pm UTC](https://boards.straightdope.com/t/random-numbers-for-dummies-me-please/311765/14 "2005-07-10T17:59:38Z")

</div>

> [@TJdude825](#):
>
> If I’m not mistaken, things like [this](http://www.lavarnd.org/what/how-it-works.html) are truly random.

“The Heisenberg Uncertainty Principle suggests that you cannot measure, with perfection, any chaotic source.”

---

<div class="post-metadata">

### Author: ![micco](https://avatars.discourse-cdn.com/v4/letter/m/5f8ce5/32.png) [@micco](https://boards.straightdope.com/u/micco)
#### Post date: [July 10, 2005, 8:00pm UTC](https://boards.straightdope.com/t/random-numbers-for-dummies-me-please/311765/15 "2005-07-10T20:00:09Z")

</div>

> [@RM Mentock](#):
>
> “The Heisenberg Uncertainty Principle suggests that you cannot measure, with perfection, any chaotic source.”

FWIW, chaos is deterministic, not random.

I think the Heisenberg Uncertainty Principle would say you can’t perfectly measure any system, whether it’s chaotic, random or just sitting there doing nothing. That is, the uncertainty principle isn’t limited to applying to certain types of systems.

---

<div class="post-metadata">

### Author: ![SenorBeef](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/senorbeef/32/2220_2.png) [@SenorBeef](https://boards.straightdope.com/u/SenorBeef)
#### Post date: [July 10, 2005, 8:36pm UTC](https://boards.straightdope.com/t/random-numbers-for-dummies-me-please/311765/16 "2005-07-10T20:36:12Z")

</div>

Online poker sites claim to use entropy given by using input (mouse movements and such) and thermal-noise based random number generators. They’re really expensive devices that basically detect miniscule amounts of heat change that naturally occurs more or less randomly.

---

<div class="post-metadata">

### Author: ![Derleth](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Derleth](https://boards.straightdope.com/u/Derleth)
#### Post date: [July 10, 2005, 9:59pm UTC](https://boards.straightdope.com/t/random-numbers-for-dummies-me-please/311765/17 "2005-07-10T21:59:30Z")

</div>

> [@SenorBeef](#):
>
> Online poker sites claim to use entropy given by using input (mouse movements and such) and thermal-noise based random number generators. They’re really expensive devices that basically detect miniscule amounts of heat change that naturally occurs more or less randomly.

Or they’re marketing hype dreamed up to get people to play possibly rigged games.

Just because we have cryptographically-secure PRNGs doesn’t mean anyone is obligated to actually use them, especially when they stand to gain if they don’t.

---

<div class="post-metadata">

### Author: ![Shalmanese](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@Shalmanese](https://boards.straightdope.com/u/Shalmanese)
#### Post date: [July 11, 2005, 12:31am UTC](https://boards.straightdope.com/t/random-numbers-for-dummies-me-please/311765/18 "2005-07-11T00:31:52Z")

</div>

> [@Derleth](#):
>
> Or they’re marketing hype dreamed up to get people to play possibly rigged games.
> 
> Just because we have cryptographically-secure PRNGs doesn’t mean anyone is obligated to actually use them, especially when they stand to gain if they don’t.

Why would you suspect that they aren’t? PartyGaming Inc recently floated for something like $10bn USD so clearly the online gambling industry isn’t starved for cash. IIRC, decent quality, commodity true RNG’s go for around $10,000 - $100,000 which should be well enough for even the most demanding applications. Seems like it would be a no-brainer for online casinos to use true RNG’s and stop the possibility of hacking.

---

<div class="post-metadata">

### Author: ![RM\_Mentock](https://avatars.discourse-cdn.com/v4/letter/r/e274bd/32.png) [@RM\_Mentock](https://boards.straightdope.com/u/RM_Mentock)
#### Post date: [July 11, 2005, 4:03am UTC](https://boards.straightdope.com/t/random-numbers-for-dummies-me-please/311765/19 "2005-07-11T04:03:46Z")

</div>

> [@Shalmanese](#):
>
> Seems like it would be a no-brainer for online casinos to use true RNG’s and stop the possibility of hacking.

Unless they _didn’t_ have the money, weren’t legitimate, and were seeking quick ways to raise cash. But I guess that’s what **Derleth** said.

---

<div class="post-metadata">

### Author: ![micco](https://avatars.discourse-cdn.com/v4/letter/m/5f8ce5/32.png) [@micco](https://boards.straightdope.com/u/micco)
#### Post date: [July 11, 2005, 1:03pm UTC](https://boards.straightdope.com/t/random-numbers-for-dummies-me-please/311765/20 "2005-07-11T13:03:21Z")

</div>

> [@RM Mentock](#):
>
> “The Heisenberg Uncertainty Principle suggests that you cannot measure, with perfection, any chaotic source.”

On re-read, I just realized that you were quoting from the linked page. They’re admiting their data source is chaotic (i.e. deterministic, not random) but the fact that they are unable to measure it precisely introduces enough error to make it a better pseudo-random than if you could measure precisely. Very clever.

[Next page](https://boards.straightdope.com/t/random-numbers-for-dummies-me-please/311765.md?page=2)
