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

501 Upvotes

178 comments sorted by

View all comments

Show parent comment

287

u/IBJON Jan 27 '24

Cloudflare generates their seeds using a wall of lavalamps and a camera. 

112

u/theusualguy512 Jan 27 '24

Apparently according to their website, they weren't the first ones who did it either (Silicon Graphics had seemingly patented it in 1996 but the patent expired).

They mix the lava lamp data with the ones generated from the Linux OS to ensure maximum entropy.

It's generally an interesting rabbit hole to fall into although I honestly do not understand the mathematics behind many of the algorithms for pseudorandom numbers and why they are proven to be mirroring random distributions.

Two popular algorithms for pseudorandom numbers according to Wikipedia seem to be the Mersenne Twister and PCG, Python uses PCG64 by default.

16

u/[deleted] Jan 28 '24

Well if Silicon Graphics did it that we can be sure NVidia ripped it off and did it.

0

u/[deleted] Jan 29 '24

I wonder if mixing the lava lamps with the Linux stuff actually makes it worse.. because it's possible that the exact state of the Linux box is influencing the lava lamps.

I'm mostly kidding, but chaos is strange like that.

18

u/freddfx Jan 27 '24

Cloudflare's write-up seems to also answer OP's question. https://www.cloudflare.com/learning/ssl/lava-lamp-encryption/

26

u/deelowe Jan 27 '24

When I worked at google we installed special devices in the DC that used radioactive decay to generate true randomness.

6

u/[deleted] Jan 28 '24

tell me more ?!?!

1

u/Astazha Jan 29 '24

The timing of a decay of any individual unstable nucleus is unpredictable. A group of a particular kind of nucleus has a half-life, a time in which approximately half of them will have decayed. But the process to get there is erratic. If you listen to the counts of a detector near a nuclear source there's no pattern to the clicks. The time between one decay and the next is an accessible source of randomness.

1

u/[deleted] Jan 29 '24

Yes super interesting I’m aware of the stochastic process of decay at the single atom level where as there are constant half-lives when zooming out and looking at the overall decay of element.

I’m curious what element they use and what the chips/device is that they use. It’s all so interesting and really why I gravitated towards CS. The maths and physics involved is just so cool. The fact they are harness quantum mechanics to make new computer architecture is so insane.

2

u/Astazha Jan 29 '24

I don't know the details but maybe someone who does will enlighten us both.

2

u/wormhole_bloom Jan 28 '24

This is awesome

1

u/sobriety-no Jul 17 '24

I imagine there are much more hardcore ways now, such as random numbers generated by some action within the realm of unpredictable quantum physics. I dont know if this is true, I just thought it as I wrote the comment, but I can imagine it is true

0

u/[deleted] Jan 28 '24

[deleted] — view deleted comment

11

u/Acrobatic-Gazelle14 Jan 28 '24 edited Mar 08 '26

This post was mass deleted and anonymized with Redact

spoon meeting modern ghost repeat hurry cobweb rock squeal elderly

1

u/Korzag Jan 29 '24

Lava lamps are hardly a fire hazard. They're a light bulb and a bottle of non-flammable liquid. Put a breaker on the circuit like any circuit up to code and the worst case scenario is a bottle breaks and makes a mess.

1

u/Drakeytown Jan 29 '24

Which arguably means a computer is not generating a random number, a wall of lava lamps is.

1

u/vulkur Jan 29 '24

There are also PCIE cards you can buy that generate "true" random numbers by reading background radiation or noise.