# How can computers perform random operations?

**URL:** <https://boards.straightdope.com/t/how-can-computers-perform-random-operations/37598>\
**Category:** Factual Questions\
**Created:** [October 19, 2000, 11:28pm UTC](https://boards.straightdope.com/t/how-can-computers-perform-random-operations/37598 "2000-10-19T23:28:28Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![hapaXL](https://avatars.discourse-cdn.com/v4/letter/h/94ad74/32.png) [@hapaXL](https://boards.straightdope.com/u/hapaXL)\
**Post date:** [October 19, 2000, 11:28pm UTC](https://boards.straightdope.com/t/how-can-computers-perform-random-operations/37598/1 "2000-10-19T23:28:28Z")

</div>

There might be an embarassingly easy explaination for this question (i apologize if it’s been covered–i’m new), but it has always baffled me. If a computer is designed to do exactly what it is told, how can it generate a random number or outcome? Would any results be “absolutely” random or just an approximation? Are there degrees of random-osity? I can clarify my question further if you’re confused…

---

<div class="post-metadata">

**Author:** ![zev\_steinhardt](https://avatars.discourse-cdn.com/v4/letter/z/97f17d/32.png) [@zev\_steinhardt](https://boards.straightdope.com/u/zev_steinhardt)\
**Post date:** [October 19, 2000, 11:30pm UTC](https://boards.straightdope.com/t/how-can-computers-perform-random-operations/37598/2 "2000-10-19T23:30:51Z")

</div>

> [@](#):
>
> \*Originally posted by hapaXL \*  
> \*\*There might be an embarassingly easy explaination for this question (i apologize if it’s been covered–i’m new), but it has always baffled me. If a computer is designed to do exactly what it is told, how can it generate a random number or outcome? Would any results be “absolutely” random or just an approximation? Are there degrees of random-osity? I can clarify my question further if you’re confused… \*\*

In programming (VB, C++, etc.) computers don’t perform random number generation. You have to provide a “seed” number to generate a psuedo-random result. A good choice is to use the number of milliseconds in the present system time. Since it is constantly changing, and you really can’t peg it down to any instant, it should simulate a random number for you.

Zev Steinhardt

---

<div class="post-metadata">

**Author:** ![Saltire](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/saltire/32/553_2.png) [@Saltire](https://boards.straightdope.com/u/Saltire)\
**Post date:** [October 19, 2000, 11:33pm UTC](https://boards.straightdope.com/t/how-can-computers-perform-random-operations/37598/3 "2000-10-19T23:33:56Z")

</div>

‘Random’ numbers from computers are not truly random. They are the result of a group of complex calculations, but if you know the number they start from and the operations involved, you can always predict the result. Thus, they are not strictly random.

But, they can be a very good approximation of true randomness. What they do is use a ‘seed number’ that is unpredictable. Often, this will be something like the number of milliseconds the computer has been running, or the exact number of clock cycles between noon and when the user hits a key. That value is almost random, so the result is also ‘almost’ random.

---

<div class="post-metadata">

**Author:** ![friedo](https://avatars.discourse-cdn.com/v4/letter/f/8edcca/32.png) [@friedo](https://boards.straightdope.com/u/friedo)\
**Post date:** [October 19, 2000, 11:37pm UTC](https://boards.straightdope.com/t/how-can-computers-perform-random-operations/37598/4 "2000-10-19T23:37:04Z")

</div>

The short answer is: they don’t. The previous two posters explained about seed numbers. That type of randomness does very well. However, for doing things like generating random keys for cryptography, you need REAL randomness, in which case the computer looks at things from nature, like the least significant numbers in the acceleration of a mouse, times of taps between keys, or times between beta particles flying off radioactive stuff.

---

<div class="post-metadata">

**Author:** ![Arjuna34](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@Arjuna34](https://boards.straightdope.com/u/Arjuna34)\
**Post date:** [October 19, 2000, 11:46pm UTC](https://boards.straightdope.com/t/how-can-computers-perform-random-operations/37598/5 "2000-10-19T23:46:03Z")

</div>

As friedo said, for high-quality random numbers, you need a hardware implementation. It’s not too difficult to get a few random numbers via mouse click or keyboard timing, etc., but for a continuous stream you need something like this:

[http://www-3.ibm.com/security/cryptocards/](http://www-3.ibm.com/security/cryptocards/)

It’s actually pretty difficult to build a really good random number generator in hardware, also, especially if you need a high-data rate stream.

Arjuna34

---

<div class="post-metadata">

**Author:** ![Arjuna34](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@Arjuna34](https://boards.straightdope.com/u/Arjuna34)\
**Post date:** [October 19, 2000, 11:47pm UTC](https://boards.straightdope.com/t/how-can-computers-perform-random-operations/37598/6 "2000-10-19T23:47:56Z")

</div>

For more than you probably wanted to know about pseudo-random numbers (the kind a deterministic computer program generates), try chapter 7 from this link:

[http://www.ulib.org/webRoot/Books/Numerical\_Recipes/bookcpdf.html](http://www.ulib.org/webRoot/Books/Numerical_Recipes/bookcpdf.html)

Arjuna34

---

<div class="post-metadata">

**Author:** ![\_Enery\_the\_VIII](https://avatars.discourse-cdn.com/v4/letter/_/5e9695/32.png) [@\_Enery\_the\_VIII](https://boards.straightdope.com/u/_Enery_the_VIII)\
**Post date:** [October 20, 2000, 12:06am UTC](https://boards.straightdope.com/t/how-can-computers-perform-random-operations/37598/7 "2000-10-20T00:06:05Z")

</div>

I used to program models for systems that required a random element. The pseudo-random would be used for a while, then the “real random” was needed. We couldn’t gain any confidence that random numbers were actually produced, so we plotted them. There were obvious patterns developing, that would repeat. So, we resorted to sampling the small electrical current with our probe board and just keeping the least significant digits. This proved satisfactory.

---

<div class="post-metadata">

**Author:** ![scr4](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@scr4](https://boards.straightdope.com/u/scr4)\
**Post date:** [October 20, 2000, 12:42am UTC](https://boards.straightdope.com/t/how-can-computers-perform-random-operations/37598/8 "2000-10-20T00:42:07Z")

</div>

Actually, Intel added a hardware random number generator starting with Pentium III. According to [one document](http://developer.intel.com/pressroom/archive/releases/cs111599.htm):

> [@](#):
>
> Intel’s Random Number Generator provides hardware that generates truly random numbers through the use of thermal noise to enable stronger encryption, digital signing and security protocols.

Thermal noise is just electrons moving around randomly on a wire, like Brownian motion of little particles floating on water. Thermal noise is truly random.

---

<div class="post-metadata">

**Author:** ![Astroboy14](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@Astroboy14](https://boards.straightdope.com/u/Astroboy14)\
**Post date:** [October 20, 2000, 1:31am UTC](https://boards.straightdope.com/t/how-can-computers-perform-random-operations/37598/9 "2000-10-20T01:31:53Z")

</div>

If I need a really random number (and who doesn’t on occasion?), I get my computer drunk!

A good alternative to this (if you can’t afford to give your computer a hangover) is to ask your girlfriend the following: “Honey, is it easier to tie your shoes being that short?” Wait a few miliseconds, and she’ll whop you over the head with your keyboard… guaranteed to generate lots of random numbers!

---

<div class="post-metadata">

**Author:** ![Arjuna34](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@Arjuna34](https://boards.straightdope.com/u/Arjuna34)\
**Post date:** [October 20, 2000, 1:53am UTC](https://boards.straightdope.com/t/how-can-computers-perform-random-operations/37598/10 "2000-10-20T01:53:44Z")

</div>

> [@](#):
>
> \*Originally posted by scr4 \*  
> \*\*  
> Thermal noise is just electrons moving around randomly on a wire, like Brownian motion of little particles floating on water. Thermal noise is truly random. \*\*

The problem with thermal noise is pickup of surrounding signals, such as PC clock, bus noise, etc. This tends to synchronize the “random” thermal noise with outside events, corrupting the randomness. The thermal noise itself is still random, but superimposed on top is non-random noise. It CAN be done, but it’s tricky to do it right 🙂

Arjuna34

---

<div class="post-metadata">

**Author:** ![Chas.E](https://avatars.discourse-cdn.com/v4/letter/c/e99b99/32.png) [@Chas.E](https://boards.straightdope.com/u/Chas.E)\
**Post date:** [October 20, 2000, 8:18am UTC](https://boards.straightdope.com/t/how-can-computers-perform-random-operations/37598/11 "2000-10-20T08:18:37Z")

</div>

As a historical note, there used to be published books of random numbers. I think I recall seeing a set of random number tables in an old edition of the “CRC Rubber Tables” book, which is a standard refererance familiar to any physicist or chemist. I don’t know how these were generated, it must have been a real bitch to produce random numbers manually, with enough true randomness to satisfy picky physicists.

---

<div class="post-metadata">

**Author:** ![Chas.E](https://avatars.discourse-cdn.com/v4/letter/c/e99b99/32.png) [@Chas.E](https://boards.straightdope.com/u/Chas.E)\
**Post date:** [October 20, 2000, 8:23am UTC](https://boards.straightdope.com/t/how-can-computers-perform-random-operations/37598/12 "2000-10-20T08:23:17Z")

</div>

> [@](#):
>
> _The problem with thermal noise is pickup of surrounding signals, such as PC clock, bus noise, etc. This tends to synchronize the “random” thermal noise with outside events, corrupting the randomness. The thermal noise itself is still random, but superimposed on top is non-random noise. It CAN be done, but it’s tricky to do it right 🙂_\*

Nah, thermal noise is definitely NOT “doing it right.” You need a more reliable random phenomenon.  
I recall seeing an article many years ago (Ciarcia’s Circuit Cellar IIRC) that used radioactive decay as the random element. It detected particles emitted from a small sample of a radioactive element and used that to generate random numbers. Now THAT is how to generate a random number.

---

<div class="post-metadata">

**Author:** ![Arjuna34](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@Arjuna34](https://boards.straightdope.com/u/Arjuna34)\
**Post date:** [October 20, 2000, 12:50pm UTC](https://boards.straightdope.com/t/how-can-computers-perform-random-operations/37598/13 "2000-10-20T12:50:42Z")

</div>

> [@](#):
>
> \*Originally posted by Chas.E \*  
> \*\*
> 
> > [@](#):
> >
> > _The problem with thermal noise is pickup of surrounding signals, such as PC clock, bus noise, etc. This tends to synchronize the “random” thermal noise with outside events, corrupting the randomness. The thermal noise itself is still random, but superimposed on top is non-random noise. It CAN be done, but it’s tricky to do it right 🙂_\*
> 
> Nah, thermal noise is definitely NOT “doing it right.” You need a more reliable random phenomenon.  
> I recall seeing an article many years ago (Ciarcia’s Circuit Cellar IIRC) that used radioactive decay as the random element. It detected particles emitted from a small sample of a radioactive element and used that to generate random numbers. Now THAT is how to generate a random number. \*\*

I agree, radioactive decay is a bettery source than thermal noise, but I don’t think it’s easy to get a 10 MB/s random stream out of it 🙂 Especially if it’s going into the slot of a PC sitting at waist level 😉

Arjuna34

---

<div class="post-metadata">

**Author:** ![kferr](https://avatars.discourse-cdn.com/v4/letter/k/71e660/32.png) [@kferr](https://boards.straightdope.com/u/kferr)\
**Post date:** [October 20, 2000, 1:22pm UTC](https://boards.straightdope.com/t/how-can-computers-perform-random-operations/37598/14 "2000-10-20T13:22:05Z")

</div>

Here’s a site that uses lava lamps to generate randoms.  
[http://lavarand.sgi.com](http://lavarand.sgi.com)

---

<div class="post-metadata">

**Author:** ![gazpacho](https://avatars.discourse-cdn.com/v4/letter/g/6f9a4e/32.png) [@gazpacho](https://boards.straightdope.com/u/gazpacho)\
**Post date:** [October 20, 2000, 2:26pm UTC](https://boards.straightdope.com/t/how-can-computers-perform-random-operations/37598/15 "2000-10-20T14:26:25Z")

</div>

Why is thermal noise not a good source of random numbers?

---

<div class="post-metadata">

**Author:** ![Arjuna34](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@Arjuna34](https://boards.straightdope.com/u/Arjuna34)\
**Post date:** [October 20, 2000, 2:56pm UTC](https://boards.straightdope.com/t/how-can-computers-perform-random-operations/37598/16 "2000-10-20T14:56:13Z")

</div>

In an ideal situation thermal noise would be fine. This ideal situation would have a thermal noise generating element (i.e. a resistor or diode) at a constant temperature, with no outside RF or other noise hitting it. Also, to measure the noise on the device, an infinite impedance voltage (or zero impedance current) measuring circuit would be used.

In real life, the device isn’t at a constant temperature- it’s fluctuating, which affects the stream of random numbers. Also, the circuit measuring the noise has some effect on the noise. Outside sources of noise can grow large enough to interfere with the random noise element. It’s not impossible to manage, but it’s not real simple to make a really good thermal noise random number generator. It’s very easy to make a half-way decent one, though, which kept in its own shield box outside of a noisy PC, is OK for many purposes.

The advantage of radioactive decay is that most outside influences have absolutely no affect on the decay rate.

Arjuna34

---

<div class="post-metadata">

**Author:** ![Kyberneticist](https://avatars.discourse-cdn.com/v4/letter/k/dc4da7/32.png) [@Kyberneticist](https://boards.straightdope.com/u/Kyberneticist)\
**Post date:** [October 20, 2000, 4:36pm UTC](https://boards.straightdope.com/t/how-can-computers-perform-random-operations/37598/17 "2000-10-20T16:36:10Z")

</div>

> [@](#):
>
> \*Originally posted by kferr \*  
> \*\*Here’s a site that uses lava lamps to generate randoms.  
> [http://lavarand.sgi.com](http://lavarand.sgi.com) \*\*

Would a lava lamp be really random though? One wonders if it couldn’t end up with patterns imposed, much like in the case of the PIII.

---

<div class="post-metadata">

**Author:** ![Kyberneticist](https://avatars.discourse-cdn.com/v4/letter/k/dc4da7/32.png) [@Kyberneticist](https://boards.straightdope.com/u/Kyberneticist)\
**Post date:** [October 20, 2000, 4:38pm UTC](https://boards.straightdope.com/t/how-can-computers-perform-random-operations/37598/18 "2000-10-20T16:38:03Z")

</div>

> [@](#):
>
> \*Originally posted by Arjuna34 \*  
> \*\*  
> The advantage of radioactive decay is that most outside influences have absolutely no affect on the decay rate.  
> \*\*

How about this? Maybe levels of radon gas seeping into houses varies based upon temperature/time of day. (soil expansion, or air temperature) The radioactive gas then slightly screws up the random number generator in a predictable pattern. 🙂

---

<div class="post-metadata">

**Author:** ![Arjuna34](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@Arjuna34](https://boards.straightdope.com/u/Arjuna34)\
**Post date:** [October 20, 2000, 4:58pm UTC](https://boards.straightdope.com/t/how-can-computers-perform-random-operations/37598/19 "2000-10-20T16:58:54Z")

</div>

> [@](#):
>
> \*Originally posted by Kyberneticist \*  
> \*\*
> 
> > [@](#):
> >
> > \*Originally posted by Arjuna34 \*  
> > \*\*  
> > The advantage of radioactive decay is that most outside influences have absolutely no affect on the decay rate.  
> > \*\*
> 
> How about this? Maybe levels of radon gas seeping into houses varies based upon temperature/time of day. (soil expansion, or air temperature) The radioactive gas then slightly screws up the random number generator in a predictable pattern. 🙂 \*\*

Um, well, I did say “most” 🙂  
You’d have to shield against that too, but since radon gives off alpha particles, it would be pretty easy.

Arjuna34

---

<div class="post-metadata">

**Author:** ![John\_Kentzel-Griffin](https://avatars.discourse-cdn.com/v4/letter/j/ccd318/32.png) [@John\_Kentzel-Griffin](https://boards.straightdope.com/u/John_Kentzel-Griffin)\
**Post date:** [October 20, 2000, 5:37pm UTC](https://boards.straightdope.com/t/how-can-computers-perform-random-operations/37598/20 "2000-10-20T17:37:32Z")

</div>

> [@](#):
>
> \*Originally posted by \*\*\*Arjuna34 \*\*  
> The advantage of radioactive decay is that most outside influences have absolutely no affect on the decay rate.

Just be sure not to try to generate random numbers during, say, the Academy Awards or the Super Bowl. See [The Conscious Universe](http://boards.straightdope.com/sdmb/showthread.php?threadid=40714).

[Next page](https://boards.straightdope.com/t/how-can-computers-perform-random-operations/37598.md?page=2)
