Is it possible to generate truly random numbers using a computer?

24.5k Views Asked by At

I know that there are many algorithms to generate pseudorandom numbers but is it possible to generate truly random numbers using a computer program?

9

There are 9 best solutions below

1
On BEST ANSWER

This is a good question, but to dig into it we have to look at the underlying assumptions.

First, for the purpose at hand, it doesn't really make sense to say that a number itself is random. There is a sense of a particular number being random from Kolmogorov complexity, but that is not what is intended here. Instead, what we are interested in might be called a random process - a process that generates a sequence of numbers so that the sequence satisfies some particular probability distribution. We want to know if a computer can generate a sequence of numbers in a random manner.

The next question is what we mean by "using a computer program". If we take a "computer program" to be a completely deterministic algorithm, then it will not be able to generate numbers in a truly random manner. There is no computer program which could be simulated entirely by paper and pencil - deterministically - which generates numbers in a random manner. The next number in the sequence is always completely predictable!

However, if we are willing to add additional hardware, then it might become able. This is a broader notion of "program". For example, the machines used to draw winning numbers for a lottery are designed, essentially, to try to generate numbers in a random manner. There is no reason that one of these could not be connected to a computer and automated. So, if we accept that the lottery can generate numbers randomly, so can a computer.

There are faster methods, as well. Some operating systems try to gather random information from the environment, store this information, and then return it when asked to generate a random number. This is not a deterministic process, but theoretically it does generate numbers in a random manner. For example, the computer can measure white noise, or can measure the timing of various events like keystrokes and packet arrivals, and combine these in a theoretically valid way to generate numbers randomly.

The final issue is philosophical. Some might believe that the entire universe is deterministic, and therefore nothing is ever random. However, that objection is too far removed for the present conversation. If we want to ask whether computers can generate numbers in a random manner, we normally take it as a given that something could generate numbers in a random manner, so that we can focus on whether computers can do so.

7
On

The answer is no, but you first need to give a precise definition of randomness. I suggest you to read the wikipedia entry Algorithmically random sequence. If you use Martin-Löf's definition (a sequence is random if there is a uniform bound on the compressibility of its initial segments), it can be proved that no random sequence is decidable, computably enumerable, or co-computably-enumerable.

8
On

After searching the Internet, I have decided to answer my own question here. It is possible to generate truly random numbers. Random numbers are generated from random unpredictable processes like thermal or atmospheric noises, cosmic radiations, etc. We need special hardware or sensors which can measure such processes and there could be a program which can produce a number from the input of random events. As this method uses random events rather than a pre-defined algorithm, it can generate a truly random number.

You can find one such online solution at https://www.random.org/. Random.org uses atmospheric noise to create randomness.

Finally, here is a joke:

Random number

3
On

I do know of one tool that uses radioactive decay to generate true random numbers, found here.

Generating true randomness from a simple computer with no extra hardware is not possible to my knowledge.

2
On

Yes there are random events.

Yes you can use a computer with a computer program to measure these and translate them to numbers.

This way you can have your program outputting truly random numbers

The philosophical question would be: would you have a computer program generating random numbers or a: "phenomena measuring" program where the phenomenon happens to have a random factor.

Because your computer program is definitely not generating randomness, it's merely using it.

2
On

Yes from a theoretical point of view, not from a practical point of view.

It is possible with a program accessing the wifi module in off-the-shelf computers. The idea behind this is described here: The random changes in noise level are recorded. This noise is generally accepted as being random (just turn your AM radio to some unoccupied frequency at daytime and listen to the noise the atmosphere produces. The same happens on the ~2 GHz frequencies our wifi modules operate on.). I think they follow some kind of poisson process, so the time between noise changes follows some exponential distribution.

Maybe one could also use turning objects like the cooling fan or the hard disk as some kind of wheel of Fortune since their rotation speed can be controlled and recorded by software.

However, such random numbers tend to have one big drawback: You don't know their true distribution. So they are useless for most applications, except if you take the random number to seed a ordinary pseudo random number generator (pRNG). Then the resulting pseudo random numbers are a bit less "pseudo" but still have a known (frequency) distribution.

Sources of useful randomness with a better understood distribution usually need devices that are no longer part of usual computers. Such devices need to comply to narrow specifications in order to produce the desired probabilities. Usual computers do not: You don't know how much your cooling fan's bearing is worn-out, which random noise your wifi actucally receives etc.

Another downside: Generating real random numbers is much slower than pRNGs are, even if you have a specialized device that observes some radioactive decay in order to produce random numbers. So you may end up again with producing only the seed for the pRNG at random.

4
On

Anyone with some I/O programming skills would be able to generate it. Not intending to patent it :-( therefore, every time you need a random number run the following algorithm:

  1. Move to a noisy place. The noisier the better; the more different noises you can listen the better, try not to use a place where a single big noise is dominating. A NY or most big cities at noon would be fine (you don’t really need to bother a lot with that, moving to your balcony may be enough);
  2. Turn on your device microphone;
  3. Record the noise;
  4. Digitize the recorded signal;
  5. Normalize to the highest value of the recorded noise i.e., highest value=1;
  6. Take the value on the $\rm n^{th}$ second of recording (provided you have recorded at least $\rm n$ seconds of noise obviously), for example the value in the $\rm 5^{th}$ second. Let’s name this value as $\rm V$, therefore $\rm V=V(n)$. Ideally $\rm n$ should be generated by any (pseudo)random number generator of your programming language or API’s you are using, giving you a second layer of randomness.
  7. Multiply $\rm V$ with the Highest Integer (or float if you want) that your system provides and your Random number $\rm R$ will be $\rm R=V×Integer.MaxValue$.

UPDATE: For a truly random number, create a background worker and repeat this algorithm in an infinite loop. However, this time use the live streaming from your device (or attached) microphone and not a record. Therefore any time someone interrupts you he will actually help you by providing (unexpected) noise. The same happens if your neighbor call his son, or close is car dor. Present moment cannot be repeated absolutely. This even solves the problem of needing many random numbers.

0
On

Yes, but there must be some random input. For example, the program can ask the user for a random number and then print it to the screen. Most of the other answers are sophisticated variants on this.

A deterministic Turing machine with a given "input" (initial tape, state of memory or whatever it is) will not generate random numbers.

0
On

In our cybersecurity lecture we were told, that you could use the way somebody types on his keyboard as a generator for pseudorandomness and then use the Von-Neumann-Correctur to get a real random number.

Von-Neumann-Correctur: Take two outputs from the biased pseudorandom generator.

If they are (00) or (11) throw them away and query new ones. If they are (10) output 1 and for (01) output 0.