# Is it true that computers can't generate true random?

**URL:** <https://boards.straightdope.com/t/is-it-true-that-computers-cant-generate-true-random/549685>\
**Category:** Factual Questions\
**Created:** [August 9, 2010, 8:41am UTC](https://boards.straightdope.com/t/is-it-true-that-computers-cant-generate-true-random/549685 "2010-08-09T08:41:30Z")\
**Posts on this page:** 19\
**Page:** 2

<div class="post-metadata">

**Author:** ![Indistinguishable](https://avatars.discourse-cdn.com/v4/letter/i/90ced4/32.png) [@Indistinguishable](https://boards.straightdope.com/u/Indistinguishable)\
**Post date:** [August 10, 2010, 2:22am UTC](https://boards.straightdope.com/t/is-it-true-that-computers-cant-generate-true-random/549685/21 "2010-08-10T02:22:21Z")

</div>

> [@Chronos](#):
>
> There are actually theorems that address this, and if the information really is there somehow, that information can be transmitted across space faster than c, and even backwards in time. If you’d prefer a model without FTL or time-reversed communication, then you’re forced to conclude that what goes on in quantum mechanics really is random.

Well, that’s a bit strong. You could always believe the entire future history of the universe is hiding in every particle somewhere, and each is at all times just following this script, with no need for faster-than-light (or indeed any) communication of the script since everyone already has a copy…

It would be a silly and ultimately meaningless way of looking at things. But if one is dedicated to seeing things deterministically for whatever (probably silly and ultimately misguided) reason, it is an available option.

---

<div class="post-metadata">

**Author:** ![Shagnasty](https://avatars.discourse-cdn.com/v4/letter/s/9dc877/32.png) [@Shagnasty](https://boards.straightdope.com/u/Shagnasty)\
**Post date:** [August 10, 2010, 2:35am UTC](https://boards.straightdope.com/t/is-it-true-that-computers-cant-generate-true-random/549685/22 "2010-08-10T02:35:57Z")

</div>

This is one of those questions that someone could ask you and the answer could spawn anything from someone spouting off “yes, flip a coin” to understanding the meaning of life, the universe, and everything.

Computers can generate true random numbers as far as we are concerned. If you don’t believe me, just buy [one of these quantum optics number generator cards for your PC](http://www.idquantique.com/true-random-number-generator/quantis-usb-pcie-pci.html). Just wait for it to be delivered and plug it in to your computer. Done deal. Those are real random numbers and not pseudo-random numbers. I understand the extreme hair-splitting involved in some of this but the fact that you can buy a standard computer card to do it is plenty good enough for me.

---

<div class="post-metadata">

**Author:** ![Jet\_Jaguar](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/jet_jaguar/32/3562_2.png) [@Jet\_Jaguar](https://boards.straightdope.com/u/Jet_Jaguar)\
**Post date:** [August 10, 2010, 3:35am UTC](https://boards.straightdope.com/t/is-it-true-that-computers-cant-generate-true-random/549685/23 "2010-08-10T03:35:57Z")

</div>

I used to use the pseudorandom nature to my advantage. When I was a kid, I’d write my own computer games on an Apple IIe. Back then, memory was at a premium - my computer had 128K of RAM and it was considered a “power system” at the time, and floppy discs held (IIRC) 140K. For games with large (for the day) databases, it wasn’t necessary to save all of the data, merely save the seed and “randomly” regenerate it as needed. As long as you always started with the same seed, the resulting data would be the same.

---

<div class="post-metadata">

**Author:** ![Chronos](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/chronos/32/134_2.png) [@Chronos](https://boards.straightdope.com/u/Chronos)\
**Post date:** [August 10, 2010, 6:45am UTC](https://boards.straightdope.com/t/is-it-true-that-computers-cant-generate-true-random/549685/24 "2010-08-10T06:45:42Z")

</div>

This is also true. The classic Atari game Pitfall, for instance, fit entirely on a 4 kilobyte cartridge, despite having 255 different screens of action. There’s no way you could fit the entire map on the cartridge (along with all of the game-engine code, sprites, etc.), so it was pseudorandomly generated instead.

---

<div class="post-metadata">

**Author:** ![BigT](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/bigt/32/12044_2.png) [@BigT](https://boards.straightdope.com/u/BigT)\
**Post date:** [August 10, 2010, 11:37am UTC](https://boards.straightdope.com/t/is-it-true-that-computers-cant-generate-true-random/549685/25 "2010-08-10T11:37:44Z")

</div>

Tool assisted speedrunners also use the pseudorandom numbers to their advantage. They will figure out how they have to seed the random generator to make the outcome of any random happening fit their goals.

For a hypothetical example, lets say there’s a boss in the game that randomly decides to use certain attacks. The random number is going to have to be generated from something–usually the time or some controller input. So if they time it right, and use the right inputs, the boss will not use it’s more powerful attacks, meaning it takes much less time to kill. Since a common goal is to find the absolute (as opposed to practical) shortest time possible to complete the game (hence the name speedrunner), this is quite likely to help fulfill their goal.

ETA: Another example you may have actually been more aware of–the random encounter system, very common in older RPGs. If you manipulate the random seed properly, you can make it where you have less encounters. Many games can be rigged where you avoid absolutely all random encounters.

---

<div class="post-metadata">

**Author:** ![qazwart](https://avatars.discourse-cdn.com/v4/letter/q/5fc32e/32.png) [@qazwart](https://boards.straightdope.com/u/qazwart)\
**Post date:** [August 10, 2010, 3:29pm UTC](https://boards.straightdope.com/t/is-it-true-that-computers-cant-generate-true-random/549685/26 "2010-08-10T15:29:34Z")

</div>

Here’s a cool way to generate actual random numbers: [Lava Lamps!](http://www.wired.com/wired/archive/11.08/random.html)

Of course, in newer iterations, lava lamps are no longer used. Instead, they simply take the random noise generated by a CMOS or CCD chip used in digital cameras, but that’s simply not as cool.

---

<div class="post-metadata">

**Author:** ![pulykamell](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/pulykamell/32/3166_2.png) [@pulykamell](https://boards.straightdope.com/u/pulykamell)\
**Post date:** [August 10, 2010, 3:58pm UTC](https://boards.straightdope.com/t/is-it-true-that-computers-cant-generate-true-random/549685/27 "2010-08-10T15:58:30Z")

</div>

nm

---

<div class="post-metadata">

**Author:** ![Napier](https://avatars.discourse-cdn.com/v4/letter/n/ce73a5/32.png) [@Napier](https://boards.straightdope.com/u/Napier)\
**Post date:** [August 10, 2010, 4:04pm UTC](https://boards.straightdope.com/t/is-it-true-that-computers-cant-generate-true-random/549685/28 "2010-08-10T16:04:27Z")

</div>

I have struggled to get pseudorandom numbers. In one environment, the most versatile method of nesting programming loops causes the same inner-loop sequence of random() outputs to start over again for each outer-loop. The alternative form of random() will return the same value if you call it several times within a brief period, I suspect because it reseeds itself from the clock rather than from its previous output. I have even gone to the trouble of slowly filling an array with random()'s and storing it so I can draw from it quickly when necessary.

---

<div class="post-metadata">

**Author:** ![Chronos](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/chronos/32/134_2.png) [@Chronos](https://boards.straightdope.com/u/Chronos)\
**Post date:** [August 10, 2010, 4:58pm UTC](https://boards.straightdope.com/t/is-it-true-that-computers-cant-generate-true-random/549685/29 "2010-08-10T16:58:52Z")

</div>

I think the coolest way to get random numbers on a computer is to build a contraption out of Lego that throws dice automatically, with a webcam hooked up to the computer to read them and software to count the pips.

---

<div class="post-metadata">

**Author:** ![Stealth\_Potato](https://avatars.discourse-cdn.com/v4/letter/s/d78d45/32.png) [@Stealth\_Potato](https://boards.straightdope.com/u/Stealth_Potato)\
**Post date:** [August 10, 2010, 7:33pm UTC](https://boards.straightdope.com/t/is-it-true-that-computers-cant-generate-true-random/549685/30 "2010-08-10T19:33:41Z")

</div>

> [@Napier](#):
>
> I have struggled to get pseudorandom numbers. In one environment, the most versatile method of nesting programming loops causes the same inner-loop sequence of random() outputs to start over again for each outer-loop. The alternative form of random() will return the same value if you call it several times within a brief period, I suspect because it reseeds itself from the clock rather than from its previous output.

Who wrote that random() implementation? :dubious:

The only possible way it could produce the same results repeatedly within a short time frame is if the generator were being re-seeded _every time it was called_ – most likely using the current time in seconds. It should not be re-seeding itself _at all_, let alone every time it is called!

For most purposes, the proper way to use a PRNG is to seed it _once_, usually at the start of whatever it is that you’re doing. Seeding multiple times is a great way to _reduce_ the randomness of the distribution, especially if it’s done carelessly. PRNGs are simple beasts. A common variety is the [linear congruential generator](http://en.wikipedia.org/wiki/Linear_congruential_generator) (LCG), which produces pseudorandom numbers by applying this recurrence relation:

```auto

   
        next = (a * next + c) % m;

```

Where a, c, and m are constants (which should satisfy certain properties for good results; see the article). Seeding the PRNG simply consists of assigning a certain value to _next_ – so you can see that if you constantly reset _next_, you’re not even really using the generator anymore; your output is only going to be as “random” as the source of your seeds. (Which, in the case of a clock, is not very random at all.)

> [@](#):
>
> I have even gone to the trouble of slowly filling an array with random()'s and storing it so I can draw from it quickly when necessary.

There should never be any need to do this! Just seed the generator once at the beginning of the program, then call random() every time you need a pseudo-random number. If that doesn’t produce satisfactory results, then this random() is horribly broken and you should probably just use whatever is in the standard libraries for your platform instead.

---

<div class="post-metadata">

**Author:** ![Chronos](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/chronos/32/134_2.png) [@Chronos](https://boards.straightdope.com/u/Chronos)\
**Post date:** [August 10, 2010, 7:52pm UTC](https://boards.straightdope.com/t/is-it-true-that-computers-cant-generate-true-random/549685/31 "2010-08-10T19:52:27Z")

</div>

It might be a very restricted platform (say, an internal scripting language for some application) for which that poorly-implemented function _is_ the standard library version.

Is the LCG the algorithm that results in streaky diagonal lines across the screen if you plot “random” points? That was always a fun exercise in my elementary-school programming days.

---

<div class="post-metadata">

**Author:** ![Pasta](https://avatars.discourse-cdn.com/v4/letter/p/ecccb3/32.png) [@Pasta](https://boards.straightdope.com/u/Pasta)\
**Post date:** [August 10, 2010, 8:03pm UTC](https://boards.straightdope.com/t/is-it-true-that-computers-cant-generate-true-random/549685/32 "2010-08-10T20:03:16Z")

</div>

> [@](#):
>
> Is the LCG the algorithm that results in streaky diagonal lines across the screen if you plot “random” points? That was always a fun exercise in my elementary-school programming days.

Yep, that’s the one.

My go-to PRNG is the [Mersenne twister](http://en.wikipedia.org/wiki/Mersenne_twister), which has beautiful randomness yet exceptional speed.

---

<div class="post-metadata">

**Author:** ![TriPolar](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/tripolar/32/3008_2.png) [@TriPolar](https://boards.straightdope.com/u/TriPolar)\
**Post date:** [August 10, 2010, 8:57pm UTC](https://boards.straightdope.com/t/is-it-true-that-computers-cant-generate-true-random/549685/33 "2010-08-10T20:57:12Z")

</div>

MaxTheVool could use a reversible random number generator here: [http://boards.straightdope.com/sdmb/showthread.php?t=573760](http://boards.straightdope.com/sdmb/showthread.php?t=573760)  
In his case, he would need to be able to generate the nth random number based on sequence, and in reverse derive the sequence from the random number. His approach was to use a hashing algorithm, so this thread makes me curious about the relationship between PRNGs and hashing. Hashing should ‘randomly’ distribute sequential numbers across a range. These topics have me curious about the relationship between the two concepts of randomness used in these different applications.

---

<div class="post-metadata">

**Author:** ![Napier](https://avatars.discourse-cdn.com/v4/letter/n/ce73a5/32.png) [@Napier](https://boards.straightdope.com/u/Napier)\
**Post date:** [August 11, 2010, 12:51am UTC](https://boards.straightdope.com/t/is-it-true-that-computers-cant-generate-true-random/549685/34 "2010-08-11T00:51:50Z")

</div>

> [@Stealth\_Potato](#):
>
> Who wrote that random() implementation?
> 
> The only possible way it could produce the same results repeatedly within a short time frame is if the generator were being re-seeded _every time it was called_ – most likely using the current time in seconds. It should not be re-seeding itself _at all_, let alone every time it is called!
> 
> If that doesn’t produce satisfactory results, then this random() is horribly broken and you should probably just use whatever is in the standard libraries for your platform instead.

It’s a very restricted platform, an internal scripting language for some application, for which that poorly-implemented function is the standard library version.

Oh… Hi, Chronos! Nice to hear from you!

Anyway, I didn’t say what I meant clearly about “reseeding”, but I think you got it. I’m actually using two scripting languages that both apparently share the feature that calling random() without an argument uses a clock value that only updates every few milliseconds as the seed, AND starts the sequence over, so it’s using the fresh seed rather than its previous result.

In one of these languages, there are two ways of doing loops. The simpler method of looping is only allowed inside certain kinds of subroutines, and in this method you normally use random(3034584357) to return random numbers, with some long seed typed by hitting lots of number keys clumsily. This produces a sequence that looks random. However, every time you run the program, it produces the same sequence. Now, the fancier way of looping has the same effect as running that part of the program again and again, including starting the pseudorandom sequence over again. There are actually reasons one might want to do this, but humorously this means there’s really no practical means of just generating pseudorandom numbers that always look random, that are always unpredictable.

---

<div class="post-metadata">

**Author:** ![constanze](https://avatars.discourse-cdn.com/v4/letter/c/f9ae1b/32.png) [@constanze](https://boards.straightdope.com/u/constanze)\
**Post date:** [August 11, 2010, 12:47pm UTC](https://boards.straightdope.com/t/is-it-true-that-computers-cant-generate-true-random/549685/35 "2010-08-11T12:47:44Z")

</div>

> [@Chimi](#):
>
> Of course, in the same way that a computer can’t generate a random number, nothing else can either…if you look at it with enough computational power. Sure, if any of us throw a balanced die, or cut to a single card in a well-shuffled pack, it’s random to us…but not to the universe.
> 
> If you toss a die, the outcome is written before it leaves your hand. If you could see the angle it dropped at, the orientation of the die, the force you chuck it at, the drag of the table as it slides, you could predict it every time. Even if you have a friend who’s gonna bop it to change it up a little bit, the how and when are written in electric fire in his head before he does, and that can be accounted for too.
> 
> With enough knowledge, you can know how the atoms will bounce off of each other, making nothing truly random. Everything can be traced back, cause to cause, to the beginning.
> 
> And that’s why I don’t mind my D&D players using a die roller program. It’s all written anyway.

Although I’m not an mathematican or expert on chaos theory, I strongly disagree and suggest that you read as soon as possible Poppers essay on this (predictably, I’ve forgotten the title of the essay and the book - but it was about determinsm and free will.) He explains why nothing is pre-determined and thus, why people have free will (I was amazed when I first read it at the approach to use advanced physics to think about free will, instead of the usual philosophic approach.

Anyway, with chaos theory and Heisenberg’S theorem and others, you can’t determine every outcome. You can predict that if you throw a dice it won’t turn into a yellow bird and fly away (unless a wizard passes through), but there are other outcomes besides the six sides, like landing on an edge, or falling of the table and rolling into a corner.😉

---

<div class="post-metadata">

**Author:** ![constanze](https://avatars.discourse-cdn.com/v4/letter/c/f9ae1b/32.png) [@constanze](https://boards.straightdope.com/u/constanze)\
**Post date:** [August 11, 2010, 12:55pm UTC](https://boards.straightdope.com/t/is-it-true-that-computers-cant-generate-true-random/549685/36 "2010-08-11T12:55:49Z")

</div>

> [@Stoid](#):
>
> Playing poker… I recall reading somewhere that computers cannot actually generate truly random cards. I can’t remember the arcane reasons why that is, but I do remember that it is.
> 
> Can anyone clarify?

This reminds me of a chapter in one of the “Science of Discworld…” books (no, these are the serious ones: one of the authors is a respected mathematican). I forgot whether it was 1, 2 or 3, but anyway, the chapter tried to explain why humans suck at random numbers. I have a hard time remembering the whole line of reasoning, but basically I think the argument was:

When you mix a pack of cards and they all appear 2,3,4 etc to ace, each colour seperated, you would not call that random, you would exclude that. However, mathematically, it is random (if you mixed good enough). It’s just that we, as humans, decide that this particular order of cards has meaning, while the other orders (which are just as likely) are “unorderd” and therefore random.

another example with numbers: The sequences

1 2 3 4 5 6 7 8 9

3 1 4 5 …

2 7 1 8 2 8 …

do all look not random (second is pi, third is euler’s number). Again, that’s only because we call certain sequences ordererd and others not. If these sequences had been gotten by throwing a non-weighted ten-sided die = random, we would have a hard time believing it. Following that line, however, every sequence has some meaning. Maybe

53972 is digit 1030 onwards of pi, or the square root of … whatever. If you look hard enough, any sequence has an order, and would therefore be excluded, so you have no randomness at all.

Or something.

---

<div class="post-metadata">

**Author:** ![qazwart](https://avatars.discourse-cdn.com/v4/letter/q/5fc32e/32.png) [@qazwart](https://boards.straightdope.com/u/qazwart)\
**Post date:** [August 11, 2010, 12:58pm UTC](https://boards.straightdope.com/t/is-it-true-that-computers-cant-generate-true-random/549685/37 "2010-08-11T12:58:09Z")

</div>

> [@Chronos](#):
>
> I think the coolest way to get random numbers on a computer is to build a contraption out of Lego that throws dice automatically, with a webcam hooked up to the computer to read them and software to count the pips.

That’s not cooler than lava lamps!

Unless, of course, you build your lego contraption out of the [Pirate Legos](http://pirates.lego.com/en-us/Default.aspx) set and toss D&D dice. Now, that would be cool.

---

<div class="post-metadata">

**Author:** ![qpw3141](https://avatars.discourse-cdn.com/v4/letter/q/6bbea6/32.png) [@qpw3141](https://boards.straightdope.com/u/qpw3141)\
**Post date:** [August 11, 2010, 1:15pm UTC](https://boards.straightdope.com/t/is-it-true-that-computers-cant-generate-true-random/549685/38 "2010-08-11T13:15:00Z")

</div>

> [@constanze](#):
>
> This reminds me of a chapter in one of the “Science of Discworld…” books (no, these are the serious ones: one of the authors is a respected mathematican). I forgot whether it was 1, 2 or 3, but anyway, the chapter tried to explain why humans suck at random numbers. I have a hard time remembering the whole line of reasoning, but basically I think the argument was:
> 
> When you mix a pack of cards and they all appear 2,3,4 etc to ace, each colour seperated, you would not call that random, you would exclude that. However, mathematically, it is random (if you mixed good enough). It’s just that we, as humans, decide that this particular order of cards has meaning, while the other orders (which are just as likely) are “unorderd” and therefore random.

Yes. Humans are absolutely hopeless at generating random sequences or deciding if sequences are random (without using some kind of maths).

Some years ago I wrote a music player program. One of it’s functions was to take lists of tracks I liked and copy them to my MP3 player together with a playlist so that they would play in a random order. (It was actually a little more complicated than that because it used three lists so that some tracks would play more frequently than others - dependent upon which list they were in.)

The program worked exactly as designed but I found it quite unusable because the the random tracks seemed so filled with patterns it sounded as if the randomisation wasn’t working.

It actually took a great deal of work to enable the program to come up with a **very** carefully ordered list (that made no use of randomisation whatsoever) and yet sounds absolutely random to me.

---

<div class="post-metadata">

**Author:** ![Bytegeist](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@Bytegeist](https://boards.straightdope.com/u/Bytegeist)\
**Post date:** [August 11, 2010, 3:51pm UTC](https://boards.straightdope.com/t/is-it-true-that-computers-cant-generate-true-random/549685/39 "2010-08-11T15:51:17Z")

</div>

> [@qazwart](#):
>
> Here’s a cool way to generate actual random numbers: [Lava Lamps!](http://www.wired.com/wired/archive/11.08/random.html)

Similar in concept (if maybe not as cool), there’s a [web service](http://www.fourmilab.ch/hotbits/) that supplies random bits fed by radioactive decay.

[Previous page](https://boards.straightdope.com/t/is-it-true-that-computers-cant-generate-true-random/549685.md?page=1)
