# Does randomness exist in computers and in nature?

In the programming language Python, you can import random and then with

random.random()


you can get a random number between $0$ and $1$.

But is it truly random or are there constraints in how computers are built that makes them not truly random number generators? For instance, could there be a bias around the first value generated or value already in memory? How would one figure out the difference?

• random() in Python by itself is not truly random, but based on the pseudorandom Mersenne twister. However, you can call SystemRandom, which uses kernel space with whitening to produce truly random numbers. – Parcly Taxel Oct 4 '16 at 11:17
• it fits too in physics and / or in philosophy and it is an excellent naive question which needs a 32 pages answer ... – user354674 Oct 4 '16 at 11:59
• At dawn time, we made at work a random generator based on hardware noise and many tools showed us that it was efficient and fast. But the next cheap generators generation uses internet random extraction technology which works well – user354674 Oct 4 '16 at 12:19
• You can't prove something is truly random in a finite time, so it is unproven that randomness occurs in nature. Of course you can prove that the limiting case of something is random, for example the position of a particle of gas after $n$ seconds in a box. – reuns Oct 4 '16 at 15:54

## 3 Answers

Pseudorandom number generators are based on well-defined mathematical sequences and are perfectly deterministic. Given the same seed, they will always generate the same sequence.

This is actually often a desirable property, as it allows you to test at will in the same conditions.

Sources of true randomness are present in a computer due to the many independent (asynchronous) tasks running and events occurring all the time. RAM content at well chosen addresses or clock time are indeed unpredictable and random. You can use this data to seed your generator every now and then.

Pseudorandom generators are designed to simulate a uniform distribution and they are validated by theory and by statistical tests to ensure that.

On the opposite, other sources of randomness may exhibit different kind of bias and non-uniformities. So in a way, they will look less random. There are probably some random sources (like described above) that you might detect by statistical tests or by discovering patterns, but this is probably a difficult exercise.

• Why this downvote ? – Yves Daoust Oct 5 '16 at 9:56
• Yves, hardware is rich of random datas. But random doesn't imply uniform distribution and one must find a way to construct seeds with this "true" random. Today, our hosting service gives us a high quality random data based on the number of the last second statistics ( and a lot of moduli ). For the vote, refer to the other comments ... – user354674 Oct 6 '16 at 17:37
• @igael: non uniform doesn't mean non random. Even for high quality cryptography, I doubt that strict uniformity ever matters. – Yves Daoust Oct 6 '16 at 18:29
• @igael silent downvotes are of no use. – Yves Daoust Oct 6 '16 at 18:30

But is it truly random or are there constraints in how computers are built that makes them not truly random number generators?

The CPU of a common computer operates deterministic, given the same input, it will always calculate the same output. So by itself it is not able to come up with a random number.

What you typically see are pseudo random generators (PRNGs) which during their deterministic run can go through a series of numbers with very large cycles and have other favourable properties, which seem to be random and can be used as approximation to random numbers.

E.g. you could involve the system time into the start value of the PRNG to make the generated number seem more random, but if you had a second exact copy of the first system with the same system time, it would generate the same numbers as the first system.

However modern computers are not isolated machines, but have sensors and network connections. These sources can be used to "harvest" entropy. (Link)

An example for this is the system behind https://www.random.org/ which measures atmospheric noise and provides it via the internet.

If there is true randomness in nature is open to debate.

In the realm of classical mechanics one assumes deterministic behaviour, but one might loose track fast due to huge number of interaction partners and sometimes extreme sensitivity to initial conditions and amplifications of errors. That is kind of practical randomness.

In the realm of quantumn mechanics one has the interesting middle ground that individual events can seem to occur at random (e.g. radioactive decay), but nonetheless the distribution of probabilities develops according to strict laws, like Schrödinger's wave equation.

How would one figure out the difference?

A simple test is using the random numbers as coordinates of points in 2D or 3D space and plot them.

The expectation is that the view plane or volume is filled up uniformly. However if pattern form, this is an indication of regularity in the sequence. E.g. see https://www.random.org/analysis/

Or see this interesting article: Strange Attractors and TCP/IP Sequence Number Analysis.

• a good abstract for a so long subject ... You may also introduce quantum and the EPR controversy – user354674 Oct 4 '16 at 12:05

many computer 'pseudo' random number generators are just calculated number sequences - some of the early ones just multiplied a number by a prime, then took a modulus - and kept the answer as the number to use for the next generation. They often repeated after ~64000 or ~16million or ~2biliion numbers were generated - the newer ones are usually longer sequences - but they are still 'pseudo' generated values - you can actually pick a seed and get the same sequence again - that's useful for simulation, where you might want to use the same randoms every time whilst testing.

Anyway, pseudo random numbers are a bit useless for encryption, or anything where we don't want the user to 'guess' the value we used - so there are better versions that use computer 'entropy' - processor ticks, mouse moves, time at start up, time processes submitted etc - to add (what people hope is) genuine 'randomness' to values.

A good random number generator should be free from bias, it should produce results that appear statistically random - an example of non-randomness is if 0 and 1 are generated with too many/too few ruins of 0's and 1's - as an example.

• It would not be my answer but I don't understand the downvote ... – user354674 Oct 4 '16 at 12:01
• @igael All answers have one downvote - I presume by a click-happy troll or something of the like. – 5xum Oct 4 '16 at 14:22
• @igael I've seen all manner of downvotes - often on unusual questions where the questioner HAS tried to make their point clear. Thanks for your support! – Cato Oct 4 '16 at 14:28