r/AskProgramming • u/Nand-X • Nov 02 '20
Does randomness really exist in computers, where everything has to be an output of a logical calculation at the core of a computer's hardware? Is it really a random result that a random number picker out of a set of numbers gives you?
Thank you
60
u/ggrnw27 Nov 02 '20
No, most use a pseudorandom number generator. Statistically they’re random, but if you know what algorithm is being used as well as the initial conditions (the seed), you can determine the exact sequence. There are hardware random number generators out there that use a truly random physical process to generate random numbers, but these are really only used in applications like cryptography that require true randomness
28
Nov 03 '20 edited Nov 03 '20
CloudFlare uses a bunch of lava lamps in series and a camera that translate the image into a long string / hash that is used as the seed for their security.
EDIT: Adding video if you're interested to learn more.
13
u/mjrpereira Nov 03 '20
can you imagine someone knocking over a lamp and going,
OH NO THE INTERNET
2
u/YMK1234 Nov 03 '20
doesn't matter ... as long as you can read signal (or even just noise) from the image sensor you are perfectly fine.
3
u/mjrpereira Nov 03 '20
it was a joke :(
I get that any system disassociated to the observer (camera) device is basically random.
1
Nov 03 '20
I SO want to believe this is t true.
1
u/MarkusBerkel Nov 03 '20
It is. SGI used to use lava lamps for RNG, and created lavarand where you could get the entropy as an end user (if you trusted HTTPS and SGI).
1
8
u/YMK1234 Nov 03 '20
There are hardware random number generators out there that use a truly random physical process to generate random numbers, but these are really only used in applications like cryptography that require true randomness
BS. Any computer that interacts with the real world has sources of true randomness. And since 2015 any x86 processor comes with a Hardware RNG onboard! https://en.m.wikipedia.org/wiki/RDRAND
8
u/wikipedia_text_bot Nov 03 '20
Rdrand
RDRAND (for "read random"; known as Intel Secure Key Technology, previously known as Bull Mountain) is an instruction for returning random numbers from an Intel on-chip hardware random number generator which has been seeded by an on-chip entropy source. RDRAND is available in Ivy Bridge processors and is part of the Intel 64 and IA-32 instruction set architectures. AMD added support for the instruction in June 2015.The random number generator is compliant with security and cryptographic standards such as NIST SP 800-90A, FIPS 140-2, and ANSI X9.82.
1
u/MarkusBerkel Nov 03 '20
*sigh*
Trusting RDRAND is complicated.
If you read far enough down in the link you posted, even Ted Ts'o, one of the main EXT4 and Linux Kernel devs believes that RDRAND is not trustworthy. There's quite a bit of noise about it on the internet. Basically, b/c RDRAND whitens the output, it's very hard to discern the actual randomness; you have no insight into the entropy source after it's been whitened.
Secondly, you have to rely on it working.
Again, from your own wikipedia post:
In some Ivy Bridge versions, due to a bug, the RDRAND instruction causes an Illegal Instruction exception.[4]
and sometimes on AMD platforms, it doesn't even work, period:
https://arstechnica.com/gadgets/2019/10/how-a-months-old-amd-microcode-bug-destroyed-my-weekend/
And, academically or philosophically, this:
BS. Any computer that interacts with the real world has sources of true randomness. And since 2015 any x86 processor comes with a Hardware RNG onboard!
is a bit flawed. Randomness is hard; what you said is like saying: "Any house that has modern plumbing has sources of good clean water!" Flint, MI would like to have a word.
0
Nov 03 '20
[deleted]
1
u/YMK1234 Nov 03 '20
A math library does not use any sort of random to begin with.
2
u/royisabau5 Nov 03 '20
Well, possibly, depending on the library, but there are a lot of reasons to use random values in math. Probability and statistics, for sure.
1
u/Poddster Nov 03 '20
but these are really only used in applications like cryptography that require true randomness
Disagree.
Hardware RNG is much more common these days. Even the Raspberry Pi has a hardware random number generator on it.
33
u/volmaborke Nov 02 '20 edited Nov 02 '20
There are (usually) two types of randomness that a computer can give you:
- Pseudo randomness. In this model you start with a seed which is always different (for example, the current time to a high level of precision), and then feed it into an algorithm which gives you a bunch of numbers that are statistically random. One such algorithm is the Mersenne twister.
- True randomness. In this model, you try to gather events that are unpredictable and feed them into an entropy pool. These can be things like the nanosecond at which an ethernet packet arrived, or mouse movements/keystrokes etc. When you ask for some randomness, the OS will then give you some entropy from the pool. For the paranoid, there are interesting ways of adding randomness into the entropy pool, like pointing a webcam at a wall of lava lamps or measuring the decay of a radioactive substance.
5
u/devnullable0x00 Nov 03 '20
These are both the same thing.
The random entropy gathered from #2 is the seed in #1
7
u/volmaborke Nov 03 '20
Indeed, you're correct that in real systems #1 is regularly reseeded from #2 whenever there is some spare entropy. I left out that detail to try to avoid confusing OP.
Conceptually, imagine that for whatever reason you stop getting any more "real" entropy for a while. #1 would still be able to give you random numbers essentially forever(*), as it's using a PRNG with a seed. But #2 would theoretically block once it's entropy pool is empty.
I would really like to have written
/dev/randomand/dev/urandom, but it turns out that real systems are a bit too complex to use as examples.(*) - ok, not forever, but the cycle length of commonly used PRNGs is "long enough"
2
u/PageFault Nov 03 '20
That is not entropy, it's completely predictable, and reverable given the seed and state of the machine, and used as a tool for reverse playback in some games. A true random is not predictable, and cannot be used in this way.
-1
u/AGI_69 Nov 02 '20
The second one is not true randomness. Just because something is unpredictable, does not make it truly random. There are hidden variables, which you could in theory know. The only thing that is known to be truly random is collapse of wave function in quantum mechanics. We know, there cannot be hidden variables in play, because of Bells theorem.
9
u/Mysquff Nov 03 '20
We know, there cannot be hidden variables in play, because of Bells theorem.
Well, technically there can still be hidden variables at play, they just need to be non-local.
1
u/AGI_69 Nov 03 '20 edited Nov 03 '20
You are right, nonlocal hidden variables are not rulled out. However, literally all of the physics we currently know is local. But it is possible, that in future, we might discover something nonlocal.
5
u/Felicia_Svilling Nov 03 '20
In practice though, things like the exact heat of the processor, or the timing of Ethernet packages is going to depend on the collapse of wave functions, which we agree is truly random, and as such they are truly random as well.
1
u/AGI_69 Nov 03 '20
Not true, because of https://en.wikipedia.org/wiki/Law_of_large_numbers. The QM effects will almost always average out. The more probability events there are, the lower the variance. And because there are so many electrons, the chance of QM influencing classical physics is astronomically low.
3
u/Felicia_Svilling Nov 03 '20
What you do to get entropy here is that you look at something like processor temperature (say 60.834578093589 degrees Celsius), and then you discard everything but the last digit (9). It is true that the law of large numbers will mean that the first digits all even out, but that doesn't apply to the last digits of the number.
For a more abstract example imagine you flip a coin a number times (giving a value of 0 or 1). You add all the flips together and display them as a binary number. You then have a sequence of bits, but the probability that the last digit is 1 will always be 0.5
1
u/AGI_69 Nov 03 '20
Every single QM experiment is made in extremely low temperature, because the heat will dominate your experiment. I think you have no idea, how much energy is in 50 Celsius processor (even if you cool it at 0 Celsius), you will never be able to measure temperature gradient caused by QM. Sorry it will simply not work. It is like measuring temperature of candle on the surface of sun. There are too powerful heat flows that will sweep it away.
1
u/wikipedia_text_bot Nov 03 '20
Law Of Large Numbers
In probability theory, the law of large numbers (LLN) is a theorem that describes the result of performing the same experiment a large number of times. According to the law, the average of the results obtained from a large number of trials should be close to the expected value and will tend to become closer to the expected value as more trials are performed.The LLN is important because it guarantees stable long-term results for the averages of some random events. For example, while a casino may lose money in a single spin of the roulette wheel, its earnings will tend towards a predictable percentage over a large number of spins.
8
u/Fidodo Nov 03 '20
If you're going to go to that extent then you're essentially just arguing that randomness doesn't exist because the universe is deterministic. Maybe that's true, but it's irrelevant to the level of randomness that this discussion is about.
-8
u/AGI_69 Nov 03 '20
That is not what I said. In fact, I said the complete opposite. Please learn to read.
9
u/Fidodo Nov 03 '20
Please learn to write
-2
u/AGI_69 Nov 03 '20
Quote me on where I said
you're essentially just arguing that randomness doesn't exist because the universe is deterministic.
You are misrepresenting my views, it means either you are liar or you lack text comprehension
3
u/noratat Nov 03 '20
They're random enough for crypto-graphic purposes, which is generally what matters.
Also, while not exactly standard hardware, they do make devices specifically for capturing quantum noise as a source of true randomness.
3
Nov 02 '20
[removed] — view removed comment
-5
u/devnullable0x00 Nov 03 '20
nothing computer generated is truly random.
6
u/Fidodo Nov 03 '20
That's true, but irrelevant because we're talking about observing variables that are not computer generated, such as the physical imperfection of networking or the complexity of human inputs informed by the human brain or incredibly complex physical interactions.
-2
u/AGI_69 Nov 03 '20
It is relevant for theoretical physics and computer science. And no, it is not true, with current understanding of physics, QM is truly random, unless there are nonlocal hidden variables.
-4
u/AGI_69 Nov 03 '20
Did you read what I wrote ? I am not arguing whether something is knowable by human or not. True randomness is not define like that.
Otherwise, nothing is truly random, makikg the term pointless
Nope, quantum mechanics is truly random. We have separate terms for pseudo-random and true random for a reason. Just because it is not useful to you, does not mean it is pointless.
6
Nov 03 '20 edited Nov 03 '20
Does randomness really exist in computers, where everything has to be an output of a logical calculation at the core of a computer's hardware?
Yes.
There's nothing in theory, as far as I know, that prevents somebody from attaching an interferometer up to a computer, so I assume somebody has done it. If you want a more specific answer, you'd have to be more specific about which computers. However, the simplest parsing of "does randomness exist in computers" is, "among all computers, is there one which contains randomness," the answer would have to be most probably yes.
Is it really a random result that a random number picker out of a set of numbers gives you?
I mean, for all you know maybe I plugged an interferometer into my computer and, generated some random bits, and used them to seed my RNG. You don't know, and I'm not telling!
2
u/AGI_69 Nov 03 '20
By computer, we usually mean Universal Turing machine, which is completely deterministic and therefore can never produce true randomness.
5
Nov 03 '20
That's a reasonable point, but the question specifically brings up hardware here, so I think it is less mathematical than concerns of Turning machines.
4
u/YMK1234 Nov 03 '20
No we don't. Just because your understanding of computer is limited by software don't drag others down to that level. A computer is quite clearly a physical object that exists in the "real" world.
1
u/AGI_69 Nov 03 '20
Universal Turing machine is what computer really is, it shares the same powers and constraints and what matters to question of randomness. In Computer Science, we are not talking about your Toshiba Handibook, we are talking about "the computer" as the principal functionality, that is shared across all computers of all kinds (calculators, washing machines etc etc). Finally, sure, you can attach device and count the hair on programmers ass and call it true randomness, but calling the hair counter + computer, just a computer is just odd.
3
u/YMK1234 Nov 03 '20
No it absolutely isn't. A computer is much more than just a universal turing machine. As in, you are literally ignoring all the parts that make the thing interesting. Or make it work the way it actually does. A UTM is a useful abstraction for some scenarios in the theoretical field, but that's about it.
Also this is not /r/askcomputerscience, and op specifically said "computer" and not "universal turing machine".
1
u/AGI_69 Nov 03 '20
What parts make it interesting ? The mouse ? The printer ? If you are talking about RAM or GPU, those things do not extend computers beyond Turing machine. They are there only for speed up and therefore, they are irrelevant for discussion of whether computer can generate random numbers or not. It cant, because Turing machine cannot. I have never seen definition of "computer" as something that is capable of measuring quantum randomness.
3
u/YMK1234 Nov 03 '20
Any interaction with the real world, really.
I have never seen definition of "computer" as something that is capable of measuring quantum randomness.
I've never seen a definition that excludes it, and any modern one can do it.
1
Nov 03 '20
A Turing Machine is math, not software. It seems like a reasonable point to raise, to me.
6
u/YMK1234 Nov 03 '20
So many wrong answers here. Any modern x86 CPU has a true source of randomness built in, which you can easily achieve by reading sensor noise for example. And even before that you could buy dedicated RNGs which for example came as a small package of a radiation source to generate random fission events, which can be detected.
You cannot compute randomness, but computers do more than computing, they very much interact with the real world through their hardware, which makes them capable of randomness.
5
u/KingofGamesYami Nov 02 '20
2
u/calsosta Nov 03 '20
Thats pretty random, but I'd use this one: https://qrng.anu.edu.au/
4
u/KingofGamesYami Nov 03 '20
I picked random.org because it has an explanation of what true randomness is and that computers typically don't have it. Not as a recommendation for a service.
4
u/YMK1234 Nov 03 '20
Any modern x86 CPU these days actually comes with a source of randomness. That is true randomness generated by some sort of sensor noise.
2
u/icandoMATHs Nov 03 '20
Yes, here is a 1 sentence example-
Have a pin on a computer read the resistance/voltage/current of a wire open to air, then read the 5th digit/decimal.
2
u/MarkusBerkel Nov 03 '20
Depends on what you define as "randomness" and "computers".
And, before getting on, this thread is a perfect example of where complex questions get asked, even if OP didn't know the depth of the rabbit hole, and where learning about it on forums where non-experts, experts, practitioners, academics, and total dummies get to speak their minds is going to give you a pretty skewed idea of the answer.
"True randomness" has an information-theoretic meaning. I am not a cryptographer or a mathematician, so I'm not the best to give you the right idea. Start with Shannon, and work your way up.
A "computer", though, I can talk about. It depends on what you're asking about. If you're talking about the abstraction; i.e., mapping a physical machine (say, based on a von Neumann architecture) to a Turing machine, and therefore wondering if Turing machines can output randomness, you're right; it cannot. A Turing machine is deterministic with respect to its inputs.
OTOH, if you're asking about "computers" as the complex assembly of real, physical, modern parts like CPUs and mobo and whatnot, that machine *does* likely have access to random sources (well, at least as far as we can practically discern, b/c you cannot PROVE that anything is random). Even simple things like diodes can make "random numbers" (see avalanche noise), and it's possible to build circuits which capture that noise and turn it into random numbers.
So, a real computer, versus the theoretical abstraction, can, if sufficiently clever, generate some degree of randomness. Exactly how random the numbers are the details that a lot of folks are discussing.
But just to give you an idea of the depth of this topic, there was a time when the Linux kernel used things like keyboard timings (times between the detection of hardware keyboard events; basically, times between keystrokes) as one source for a seed for its PRNG. And that's b/c, at that time, it was believed that that timing was a bit unpredictable. OTOH, we now have machine learning models that can predict who is typing based on just key-event delays. So, not very random.
There's a whole iceberg of issues (where the question you asked is above the water, but all the issues are below) that rests on the "quality" (i.e., randomness) of any random number source. And, at the end of the day, when the philosophical issue is no longer relevant, but we just need some "random numbers, yo", the question becomes about the suitability to purpose. If you want to protect state secrets, you need to work very hard to get very high quality RNGs. If you wanna make a dice-rolling app, you don't give two shits. And those are just some of the applications of random numbers.
2
u/AGI_69 Nov 03 '20
This is beautifully written. People here seem to not appreciate the theoretical meaning and implications of "true randomness". This question is very old and deep, it troubled minds like Einstein and Bohr. In pre-quantum mechanics times, the Universe was seen as giant clockwork ( something that could be exactly simulated on Turing machine, to the smallest particle, including human minds etc), something that is completely deterministic, even Einstein was proponent of this idea to his very end. Now, we have experiments like Bells experiment, in which physicists ruled out influence of hidden local variables. Contrary to Einsteins famous quote "Universe seems to play dice". I also liked the very good remark by someone above, that there is still room for nonlocal hidden variables, truly "spooky action on distance" - it even has a name in Physics community, called Bohm interpretation of QM and it still gives hope to determinists.
The discussion about practicality and applied randomness is completely orthogonal to theoretical randomness. You can extract infinite amount of pseudo random numbers from various sources.
1
u/Fidodo Nov 03 '20
Randomness is completely at odds with what a processor should output, so just looking at the hardware inputs and outputs themselves there should be no randomness. However, it's possible to poll observable random elements, for example, you can use the temperature of the processor as a seed for the random number generator, and since it's polling an incredibly complicated physical process it is sufficiently random.
0
u/AGI_69 Nov 02 '20
Today's computers are deterministic, which means that if you know state of the computer at one point of time, you can rewind it or fast-forward it in time. The only true randomness comes from quantum mechanics
-2
u/DarkTechnocrat Nov 03 '20
A "Truly Random" sequence is defined as being Turing incomputable. No Turing machine can create such a sequence, even in principle. Everything else is pseudorandom.
edit: as pointed out below, quantum randomness is truly random.
1
Nov 03 '20
Radiation detection would do it. Put a hunk of enriched Uranium in a detection chamber, and base your random generator off where the radiation strikes. Where and when a radioactive element emits radiation is truly unpredictable (as far as we know) and thus would be a source of truly random numbers.
1
u/hunkerdown Nov 03 '20
Exactly this, these answers are based on assumptions, key one being that randomness exists at all at all. I don’t see how there could ever be definitive proof that it does, so we’re realizing that this question is asking more questions the longer you ask it... a segue into becoming agnostic.
-4
u/VirtualLife76 Nov 02 '20
Forget the language from many years ago, but it was based on the current time for the seed. The odds of hitting the same exact ms is pretty slim. So no, not really random, but random enough.
2
u/HBK05 Nov 02 '20
C++ does this..id imagine others do as well
1
u/VirtualLife76 Nov 02 '20
Thanks, was thinking it was c and/or c++. Been too long since the details of random really mattered for me.
5
u/Milnternal Nov 03 '20
Does randomness really exist in the real world? Is it really a 'random' result when you roll a dice? How do you know?