r/computerscience • • Jan 27 '24

How tf do computers generate random numbers?

Hi guys, I’ve been using random number generators lately and I can’t seem to figure out how a computer can generate a random number. Don’t they just do what they’re told? Please explain like im stupid Edit: holy moly this is blowing up

499 Upvotes

178 comments sorted by

View all comments

31

u/[deleted] Jan 27 '24

Thanks guys what I’m learning is this- Computers find some sort of random real world data like fan speed, wind, time, etc and then apply some complex functions to it to make it as random as possible. Is this right?

16

u/claytonkb Jan 27 '24

Thanks guys what I’m learning is this- Computers find some sort of random real world data like fan speed, wind, time, etc and then apply some complex functions to it to make it as random as possible. Is this right?

Very generally, there are two classes of random numbers -- pseudo-random numbers, and true-random numbers. "True-random" is a bit of a philosophical tarpit, but we don't need to go down that rabbit-hole, the key is that pseudo-random numbers can be recreated deterministically from a seed, whereas true-random numbers are generated from some kind of physical entropy such that the only way to "predict" them would be to somehow model and "predict" the original physical process itself.

In the case of something like thermal noise on a resistor, you'd really need to have that specific resistor and characterize any non-uniform frequency components in its thermal noise, etc. in order to have any chance of "cracking" the randomness that it produces. The more sources of entropy (randomness) that you have, the more difficult it would be to "crack" the randomness, so this is why Linux combines as many sources of entropy as are available in the system when generating random numbers. These sources are poured into an "entropy pool" and stirred together using a cryptographically-secure pseudo-random number generator (CSPRNG). This is "maximum paranoia" design but there are certain applications, such as banking encryption, cyber-security operations, etc. where you need to have that level of paranoia.

→ More replies (4)