Can Computers Truly Generate Random Numbers in C++?

  • Context: C/C++ 
  • Thread starter Thread starter kant
  • Start date Start date
  • Tags Tags
    Numbers Random
Click For Summary

Discussion Overview

The discussion revolves around the ability of computers to generate random numbers, particularly in the context of C++ programming. Participants explore the distinction between pseudorandom and true randomness, the mechanisms behind random number generation, and the implications of using algorithms like those for generating digits of pi.

Discussion Character

  • Debate/contested
  • Technical explanation
  • Mathematical reasoning

Main Points Raised

  • Some participants assert that deterministic machines can only produce pseudorandom numbers, which are derived from algorithms seeded by initial values such as the system clock.
  • Others describe hardware randomness as utilizing physical phenomena, such as radioactive decay, to generate true random bits.
  • A participant questions the nature of pseudorandom number generation, suggesting that algorithms can produce sequences that appear random but are ultimately deterministic based on their initial seed.
  • There is a discussion about the paradox of using a deterministic computer to extract random numbers from pi, with some arguing that the choice of the starting index (n) is not truly random, thus affecting the randomness of the output.
  • One participant introduces the pigeonhole principle, arguing that a computer with finite memory cannot explore all possible values of n, leading to repetitions and thus limiting true randomness.
  • Another participant challenges the mathematical representation of the number of possible starting points for n, leading to a clarification about the number of n-digit binary numbers possible in a given base.

Areas of Agreement / Disagreement

Participants generally agree that deterministic machines cannot produce true randomness, but there is disagreement regarding the implications of this limitation and the nature of algorithms used for generating random numbers. The discussion remains unresolved on several technical points, particularly regarding the mathematical aspects of memory and possible states.

Contextual Notes

Some limitations in the discussion include assumptions about the definitions of randomness and the dependence on specific algorithms and hardware configurations. The mathematical arguments presented are not fully resolved, leaving room for interpretation and further exploration.

kant
Messages
388
Reaction score
0
Can random numbers be produced by computers? In c++, you have functions like rand(), srand(), time(0) that more or less extract series of random numbers from a random number table. How do people produce the table in the first place?
 
Technology news on Phys.org
Detrmanistic machines cannot produce truly random numbers; they produce pseudorandom numbers. Usually these are based on congruences from an earlier internal state, seeded by the clock.

'Hardware random' information can be obtained for special purposes.
 
can you clarify these two points:



Usually these are based on congruences from an earlier internal state, seeded by the clock.



and



'Hardware random' information



thanks
 
Hardware randomness is like hooking your comoutr up to a Geiger counter and a radioactive source -- you're just sending it real random bits.

The pseudorandom number generator often works like this:

new state = ((old state * big number) modulo (other number)) + large number
 
Using CRG's example, a seed sets the "old state" to a beginning value -
Code:
old state = seconds since Jan 1 1970 + process id
new state = ((old state * big number) modulo (other number)) + large number
Hardware randomness uses arbitrary "events" in an operating system based on low-level computer hardware activity as a basis for creating a stream of bits. google for Matt Blaze's truerand program as an attempt at this sort of thing.
 
kant said:
Can random numbers be produced by computers?
There are algorithms to generate the "nth" digit of pi, the sequence would repeat unless "n" were stored and continued to be incremented each time the generator was used.
 
Jeff Reid said:
There are algorithms to generate the "nth" digit of pi, the sequence would repeat unless "n" were stored and continued to be incremented each time the generator was used.

This almost sounds paradoxical at first: the concept of using a discrete computer to "look into" the depths of pi and pull out truly random numbers. There are theorems which should prevent this kind of true randomness from ever coming from a determistic computer.

The resolution of the paradox is to realize that the initial seed value -- the index n into pi with which your generator begins -- is not truly random, but only psuedorandom.

Viewed in this light, pi is nothing more than a giant table of truly random numbers, computed on-demand, and the hard part of the problem is picking a truly random n to start reading it. Since no computer will ever be able to choose a truly random starting n, the resulting algorithm's output is still not truly random.

- Warren
 
chroot said:
Viewed in this light, pi is nothing more than a giant table of truly random numbers, computed on-demand, and the hard part of the problem is picking a truly random n to start reading it. Since no computer will ever be able to choose a truly random starting n, the resulting algorithm's output is still not truly random.

Alternately, the process of determining the nth digit of pi is just a complicated but determanistic hash function. :biggrin:
 
There's also a pigeon-hole problem here: a computer with 2^10 bits of memory, for example, can only choose one of 2^10 different starting points for n. It would be impossible for a computer of finite memory capacity to truly explore ALL of pi. This means that, at some perhaps distant time in the future, the computer will select a value for n that was previously selected.

You can do all sorts of mixing and hashing and other procedures to eliminate periodicity in the seed, but, eventually, you will always end up producing nearly random numbers. Of course, nearly random numbers are not random, though you could design a system to produce numbers to any desired degree of "randomness."

- Warren
 
  • #10
chroot said:
There's also a pigeon-hole problem here: a computer with 2^10 bits of memory, for example, can only choose one of 2^10 different starting points for n. It would be impossible for a computer of finite memory capacity to truly explore ALL of pi. This means that, at some perhaps distant time in the future, the computer will select a value for n that was previously selected.

I agree with you that the pigeonhole principle alone means that determanistic machines can't produce randomness. Your equation is off, though. A computer with 210 = 1024 bits of memory can choose not
[tex]2^{10}=1.024e3[/tex]
starting places but
[tex]2^{2^{10}}\approx1.798e308[/tex]
starting places.
 
  • #11
CRGreathouse said:
[tex]2^{10}=1.024e3[/tex]
starting places but
[tex]2^{2^{10}}\approx1.798e308[/tex]
starting places.

You lost me there. What are you talking about?

- Warren
 
  • #12
chroot said:
You lost me there. What are you talking about?

Consider base b numbers. How many n-digit numbers are possible?

b^n, e.g, in base 10, 10^3 3-digit numbers are possible.

Hence, 2^(2^10) 2^10-digit binary numbers are possible.
 
  • #13
George Jones said:
Consider base b numbers. How many n-digit numbers are possible?

b^n, e.g, in base 10, 10^3 3-digit numbers are possible.

Hence, 2^(2^10) 2^10-digit binary numbers are possible.

Exactly, thanks for the explanation.
 
  • #14
Heh, of course.

- Warren
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 21 ·
Replies
21
Views
8K
Replies
17
Views
1K
Replies
19
Views
2K
Replies
25
Views
4K
Replies
11
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K