# What's the difference between a random number and a pseudo-random number?

**URL:** <https://boards.straightdope.com/t/whats-the-difference-between-a-random-number-and-a-pseudo-random-number/605004>\
**Category:** Factual Questions\
**Created:** [December 4, 2011, 4:00am UTC](https://boards.straightdope.com/t/whats-the-difference-between-a-random-number-and-a-pseudo-random-number/605004 "2011-12-04T04:00:32Z")\
**Posts on this page:** 20\
**Page:** 2

<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:** [December 5, 2011, 12:18am UTC](https://boards.straightdope.com/t/whats-the-difference-between-a-random-number-and-a-pseudo-random-number/605004/21 "2011-12-05T00:18:03Z")

</div>

> [@Leo\_Bloom](#):
>
> Huge question then: how do NSA-types generate encryptions with entropy encoders that can be decrypted?

I’m not sure exactly what you’re asking, but to decrypt stuff (the nice way) you need to know the key (either a symmetric key or part of a public/private keypair.) Random number generators are used to make random keys.

---

<div class="post-metadata">

**Author:** ![cmyk](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/cmyk/32/3353_2.png) [@cmyk](https://boards.straightdope.com/u/cmyk)\
**Post date:** [December 5, 2011, 12:21am UTC](https://boards.straightdope.com/t/whats-the-difference-between-a-random-number-and-a-pseudo-random-number/605004/22 "2011-12-05T00:21:32Z")

</div>

> [@Chronos](#):
>
> [url=“[xkcd: Random Number](http://xkcd.com/221/)”]  
> Oh, and another couple of sources of entropy consumer computers (without a dedicated RNG module) use are the temperature of the processor (which they monitor anyway to prevent overheating) and the “quiet” input from a microphone, if one is attached.

Years ago, I can’t remember where, but I saw a blog-style post of a guy who used a web cam of the sky/clouds overhead for this sort of thing.

---

<div class="post-metadata">

**Author:** ![Andy\_L](https://avatars.discourse-cdn.com/v4/letter/a/c67d28/32.png) [@Andy\_L](https://boards.straightdope.com/u/Andy_L)\
**Post date:** [December 5, 2011, 12:47am UTC](https://boards.straightdope.com/t/whats-the-difference-between-a-random-number-and-a-pseudo-random-number/605004/23 "2011-12-05T00:47:39Z")

</div>

> [@cmyk](#):
>
> Years ago, I can’t remember where, but I saw a blog-style post of a guy who used a web cam of the sky/clouds overhead for this sort of thing.

Lava lamps are used for that too [Lavarand - Wikipedia](http://en.wikipedia.org/wiki/Lavarand)

---

<div class="post-metadata">

**Author:** ![Leo\_Bloom](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/leo_bloom/32/10377_2.png) [@Leo\_Bloom](https://boards.straightdope.com/u/Leo_Bloom)\
**Post date:** [December 5, 2011, 2:05am UTC](https://boards.straightdope.com/t/whats-the-difference-between-a-random-number-and-a-pseudo-random-number/605004/24 "2011-12-05T02:05:11Z")

</div>

> [@friedo](#):
>
> I’m not sure exactly what you’re asking, but to decrypt stuff (the nice way) you need to know the key (either a symmetric key or part of a public/private keypair.) Random number generators are used to make random keys.

Ok. I remember–broadly–those principles.

In some other thread sometime I’ll ask some dumb cryptography questions…😉

---

<div class="post-metadata">

**Author:** ![standingwave](https://avatars.discourse-cdn.com/v4/letter/s/9de0a6/32.png) [@standingwave](https://boards.straightdope.com/u/standingwave)\
**Post date:** [December 5, 2011, 3:45am UTC](https://boards.straightdope.com/t/whats-the-difference-between-a-random-number-and-a-pseudo-random-number/605004/25 "2011-12-05T03:45:12Z")

</div>

> [@friedo](#):
>
> The answer is that a deterministic machine like a computer can’t be programmed to come up with true random numbers, since a program always runs in a predictable way.

I just have to add this quote by [John Von Neumann](http://en.wikipedia.org/wiki/John_von_Neumann): _“Any one who considers arithmetical methods of producing random digits is, of course, in a state of sin.”_

---

<div class="post-metadata">

**Author:** ![filmore](https://avatars.discourse-cdn.com/v4/letter/f/7993a0/32.png) [@filmore](https://boards.straightdope.com/u/filmore)\
**Post date:** [December 5, 2011, 4:19am UTC](https://boards.straightdope.com/t/whats-the-difference-between-a-random-number-and-a-pseudo-random-number/605004/26 "2011-12-05T04:19:48Z")

</div>

Computers can’t come up with truly random numbers. They have complicated formulas which produce numbers which are random enough for most uses, but it’s just a formula. If you know the formula and the number it started with, you could compute each and every number produced.

Let’s take a simple example. Let’s say the formula the computer uses to produce random numbers is this:

R = R \*2 [The next random number is the current random number times two]

(Yes, that’s a terrible equation for random numbers, but it will work for this example.)

The seed is like setting the first random number. So if you seed it with 10, you’ll get the random numbers 20, 40, 80 … If you seed it with 15, you’ll get 30, 60, 120 …

Those “random” numbers will work for some programs which just need sort of random numbers. But if you have a security need for random numbers, those numbers aren’t random enough. A crook may be able to guess the seed number and then they will know the random number sequence. They may be able to use that knowledge to break the security key.

A common way to set the seed is by using the current system time in milliseconds. This works fine for non-security uses. But if you need random numbers for a security implementation, it’s bad. If a crook can figure out what time your program started, he can figure out the seed used and he will have a much easier time to break the security.

---

<div class="post-metadata">

**Author:** ![Voyager](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/voyager/32/133_2.png) [@Voyager](https://boards.straightdope.com/u/Voyager)\
**Post date:** [December 5, 2011, 4:35am UTC](https://boards.straightdope.com/t/whats-the-difference-between-a-random-number-and-a-pseudo-random-number/605004/27 "2011-12-05T04:35:41Z")

</div>

Here is an example of the value of deterministic pseudo-random number generators. One way of testing ICs is Built-In Self Test, (BIST) which works by using a linear feedback shift register implemented in hardware, which is basically polynomial division. These are designed to generation 2\*\*n-1 random numbers, where n is the size of the LFSR (You can’t have the all 0 value) without repeating. These get applied to the circuit, the results compressed, and then checked against the expected value. The value is predicted by simulating the patterns as applied to the circuit, and so the values had better be repeatable. They start with a seed, and various methods to move to different parts of the number space use reseeding after some time. By careful selection of the seeds you can even force the sequence to have some properties you want.

There is even a big book of polynomials, or so I’ve heard.

---

<div class="post-metadata">

**Author:** ![panamajack](https://avatars.discourse-cdn.com/v4/letter/p/47e85d/32.png) [@panamajack](https://boards.straightdope.com/u/panamajack)\
**Post date:** [December 5, 2011, 5:11am UTC](https://boards.straightdope.com/t/whats-the-difference-between-a-random-number-and-a-pseudo-random-number/605004/28 "2011-12-05T05:11:07Z")

</div>

May as well bring up the [best Amazon book review ever](http://www.amazon.com/Million-Random-Digits-Normal-Deviates/dp/0833030477).

---

<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:** [December 5, 2011, 5:17am UTC](https://boards.straightdope.com/t/whats-the-difference-between-a-random-number-and-a-pseudo-random-number/605004/29 "2011-12-05T05:17:57Z")

</div>

> [@panamajack](#):
>
> May as well bring up the [best Amazon book review ever](http://www.amazon.com/Million-Random-Digits-Normal-Deviates/dp/0833030477).

> [@](#):
>
> The book is a promising reference concept, but the execution is somewhat sloppy. Whatever algorithm they used was not fully tested. The bulk of each page seems random enough. However at the lower left and lower right of alternate pages, the number is found to increment directly.

This is why I love Amazon reviews. I almost wasted my money on that thing.

---

<div class="post-metadata">

**Author:** ![JWT\_Kottekoe](https://avatars.discourse-cdn.com/v4/letter/j/3ec8ea/32.png) [@JWT\_Kottekoe](https://boards.straightdope.com/u/JWT_Kottekoe)\
**Post date:** [December 5, 2011, 5:53am UTC](https://boards.straightdope.com/t/whats-the-difference-between-a-random-number-and-a-pseudo-random-number/605004/30 "2011-12-05T05:53:33Z")

</div>

> [@panamajack](#):
>
> May as well bring up the [best Amazon book review ever](http://www.amazon.com/Million-Random-Digits-Normal-Deviates/dp/0833030477).

[Hijack]

Which reminds me of a list I once saw of unlikely titles for math books. The only two I remember were:

- One million random numbers, in numerical order
- A short list of odd perfect numbers

P.S. I also once saw a list in Reader’s Digest of unlikely book titles. The one I liked was:

- New hope for the dead

[/Hijack]

---

<div class="post-metadata">

**Author:** ![cmyk](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/cmyk/32/3353_2.png) [@cmyk](https://boards.straightdope.com/u/cmyk)\
**Post date:** [December 5, 2011, 7:09am UTC](https://boards.straightdope.com/t/whats-the-difference-between-a-random-number-and-a-pseudo-random-number/605004/31 "2011-12-05T07:09:43Z")

</div>

> [@Andy\_L](#):
>
> Lava lamps are used for that too [Lavarand - Wikipedia](http://en.wikipedia.org/wiki/Lavarand)

Dig it.

---

<div class="post-metadata">

**Author:** ![Rigamarole](https://avatars.discourse-cdn.com/v4/letter/r/77aa72/32.png) [@Rigamarole](https://boards.straightdope.com/u/Rigamarole)\
**Post date:** [December 5, 2011, 7:48am UTC](https://boards.straightdope.com/t/whats-the-difference-between-a-random-number-and-a-pseudo-random-number/605004/32 "2011-12-05T07:48:31Z")

</div>

For all practical intents and purposes, there is no difference. It’s more of a philosophical thing that nerds like to talk about.

---

<div class="post-metadata">

**Author:** ![psychonaut](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/psychonaut/32/4655_2.png) [@psychonaut](https://boards.straightdope.com/u/psychonaut)\
**Post date:** [December 5, 2011, 8:20am UTC](https://boards.straightdope.com/t/whats-the-difference-between-a-random-number-and-a-pseudo-random-number/605004/33 "2011-12-05T08:20:46Z")

</div>

> [@Rigamarole](#):
>
> For all practical intents and purposes, there is no difference. It’s more of a philosophical thing that nerds like to talk about.

Since when are cryptography, computer animation, video games, and all the other examples posted in this thread not practical applications?

---

<div class="post-metadata">

**Author:** ![Francis\_Vaughan](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/francis_vaughan/32/3093_2.png) [@Francis\_Vaughan](https://boards.straightdope.com/u/Francis_Vaughan)\
**Post date:** [December 5, 2011, 11:40am UTC](https://boards.straightdope.com/t/whats-the-difference-between-a-random-number-and-a-pseudo-random-number/605004/34 "2011-12-05T11:40:45Z")

</div>

> [@](#):
>
> For all practical intents and purposes,

As I wrote above, the distinction is critical for almost all of experimental computational science. If the random number generators were all true random it would make the science much harder to do and significantly impact upon its practicality. There are a lot of subtleties involved that impact on practicality. So much so that the use of PRNG versus true stochastic has a clear technical divide built from the needs of the application. When you know enough about the nature of the problem the need for one versus the other is black and white, one will do, the other will not.

---

<div class="post-metadata">

**Author:** ![Rigamarole](https://avatars.discourse-cdn.com/v4/letter/r/77aa72/32.png) [@Rigamarole](https://boards.straightdope.com/u/Rigamarole)\
**Post date:** [December 5, 2011, 4:23pm UTC](https://boards.straightdope.com/t/whats-the-difference-between-a-random-number-and-a-pseudo-random-number/605004/35 "2011-12-05T16:23:29Z")

</div>

OK, OK, _most_ practical intents and purposes.

---

<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:** [December 5, 2011, 5:48pm UTC](https://boards.straightdope.com/t/whats-the-difference-between-a-random-number-and-a-pseudo-random-number/605004/36 "2011-12-05T17:48:38Z")

</div>

> [@Rigamarole](#):
>
> OK, OK, _most_ practical intents and purposes.

No public key cryptography = no ecommerce. What’s impractical about that?

---

<div class="post-metadata">

**Author:** ![cmyk](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/cmyk/32/3353_2.png) [@cmyk](https://boards.straightdope.com/u/cmyk)\
**Post date:** [December 5, 2011, 5:57pm UTC](https://boards.straightdope.com/t/whats-the-difference-between-a-random-number-and-a-pseudo-random-number/605004/37 "2011-12-05T17:57:42Z")

</div>

> [@Rigamarole](#):
>
> OK, OK, _most_ practical intents and purposes.

Hey! My grandma depends on PRN everytime her cool swirly screen saver switches on! 😉

---

<div class="post-metadata">

**Author:** ![tellyworth](https://avatars.discourse-cdn.com/v4/letter/t/977dab/32.png) [@tellyworth](https://boards.straightdope.com/u/tellyworth)\
**Post date:** [December 6, 2011, 12:20am UTC](https://boards.straightdope.com/t/whats-the-difference-between-a-random-number-and-a-pseudo-random-number/605004/38 "2011-12-06T00:20:50Z")

</div>

> [@Rigamarole](#):
>
> OK, OK, _most_ practical intents and purposes.

There are [numerous examples](http://www.cs.virginia.edu/~rjg7v/annotated.html) of security flaws caused by using a poorly seeded PRNG rather than a true source of entropy. Many don’t involve cryptography. [This one](http://www.cigital.com/papers/download/developer_gambling.php) springs to mind as a memorable example.

I’d expect any competent developer to understand the difference and know how to choose which one to use. It’s very much a practical thing, not academic or philosophical.

---

<div class="post-metadata">

**Author:** ![Blakeyrat](https://avatars.discourse-cdn.com/v4/letter/b/ecd19e/32.png) [@Blakeyrat](https://boards.straightdope.com/u/Blakeyrat)\
**Post date:** [December 6, 2011, 12:34am UTC](https://boards.straightdope.com/t/whats-the-difference-between-a-random-number-and-a-pseudo-random-number/605004/39 "2011-12-06T00:34:14Z")

</div>

If you’re a programmer, it’s worth noting that most systems have a simple PRNG used for things like Freecell (to use an above example), and a much “more random” one to use for Cryptography.

In .net, that’s System.Random for the former, and System.Security.Cryptography.RNGCryptoServiceProvider for the latter.

---

<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:** [December 6, 2011, 1:07am UTC](https://boards.straightdope.com/t/whats-the-difference-between-a-random-number-and-a-pseudo-random-number/605004/40 "2011-12-06T01:07:02Z")

</div>

And the reason you have two different ones is that your entropy pool is a valuable resource, one that you don’t want to just waste on something trivial like a game.

[Previous page](https://boards.straightdope.com/t/whats-the-difference-between-a-random-number-and-a-pseudo-random-number/605004.md?page=1)

[Next page](https://boards.straightdope.com/t/whats-the-difference-between-a-random-number-and-a-pseudo-random-number/605004.md?page=3)
