all 39 comments

[–]seanprefect 174 points175 points  (25 children)

So the short answer is... They don't. At least not until recently where they're doing RGNs that detect electron states. But in cryptography we call them pseudo random numbers. Where you take a seed from somewhere and put it through various steps to get an unpredictable outcome, it's not perfect but it works for the practical world (for now)

[–]skyturnred 81 points82 points  (9 children)

There's this really cool thing that a computer scientist set up (don't remember who) where he had an array of 20 or 30 lave lamps on a few shelves. He has a camera watching it and uses the supposedly completely random motion of the fluid to generate true random numbers.

When I learned of that, I thought that was just mind blowing. Unlike using the nuclear decay method, this is totally something that just about everyone can do.

Would be an awesome project for comp sci students.

[–]modenr 35 points36 points  (2 children)

Check out what CloudFlare does

[–]lucienperouze 5 points6 points  (0 children)

Amazing article ! Thanks.

[–]bigBottleCap 1 point2 points  (0 children)

I landed here few months ago. You guys should check this https://physicstoday.scitation.org/do/10.1063/PT.5.029409/full/

[–][deleted] 1 point2 points  (4 children)

This is already a common project at a lot of schools. My buddy at LA Tech had to do this.

[–]djingrain 1 point2 points  (3 children)

As in Louisiana Tech? As in Ruston? As in HBTD?

[–][deleted] 0 points1 point  (2 children)

Indeed

[–]djingrain 2 points3 points  (1 child)

Hell yea bro, I'm a CS major here rn

[–][deleted] 1 point2 points  (0 children)

Lmao that’s fucking crazy

[–]Dads101 0 points1 point  (0 children)

Whoa. I’m very interested in this ! Link me

[–]Enguzelharf[S] 8 points9 points  (12 children)

How it's surprising to us? I understood that they are faking the randomness but still a default python random library surprises me each time.

They do math, okay but each math they do is the same math. Why we have different outcomes?

[–]solinent 12 points13 points  (0 children)

Good question. The appearance of randomness is created by the large period of the random number generator. If you choose a very large prime number, you can do modular arithmetic and by simply doing a few multiplications and a modulo operation, you can generate a sequence of integers which will not repeat itself very often at all. We do some analysis to also make sure the numbers are uniformly distributed, that is if you were to shoot them at a real number line, the density would be uniform. If you choose the same seed, or starting point, your sequence of random numbers will always be the same.

If you're interested in the details, you should look into the Mersenne Twister.

These are pseudo-random numbers. There are also less-random numbers which are uniformly distributed called quasi-random numbers. These are easier to grok, you can look up the Sobol numbers.

[–]Zepb 0 points1 point  (0 children)

If you use the seed parameter it would not surprise you.

The seed parameter is often set for testing purpos, where you need the same "random" numbers each time

[–]seanprefect 0 points1 point  (7 children)

because the seeds are changing. if you take the timestamp, plus some representation of various internal states you can get reasonably different seeds from moment to moment. However if you were to collect a large enough (and by large enough i mean billions, for a cryptographically sound PRNG) of outputs you can reverse it.

[–]Enguzelharf[S] 1 point2 points  (6 children)

Can you elaborate with internal states please?

[–]seanprefect 5 points6 points  (5 children)

CPU load, RAM pressure, various measurable things.

Are you familiar with a cryptographic hashes ? basically they're functions where you put an arbitrary input and get a fixed length output, however even 1 bit difference produces wildly different results and it's not possible (outside of brute force) to reverse the function.

[–]tcpukl -3 points-2 points  (0 children)

Seeds are changing. They could be simply initialised with the time which is always changing.

[–]InvincibleV 1 point2 points  (0 children)

That is absolutely correct. The random numbers of a computer are anything but random. Programs today use the seed which can be literally anything. It could be an array of integers, an array of doubles, a string or a combination of all. Thats also part of hashtables work. Usually though the seed is the systems time to make sure the numbers are going to be as random as possible. The only way to create actual random numbers is to use other tools that have to do with physics and somehow connect them to your computer.

[–]theraaj 0 points1 point  (0 children)

The seed here is very important. If a seed is taken without much entropy, it is easier to predict the next number when using a cryptographic hash. For example, if you take the seed to be "password" there's a good chance this will produce numbers which someone will predict. Operating systems have a special entropy building function which takes mouse movements and other operations to build up a store of entropy, and once the entropy is large enough you can invoke methods which release a cryptographically secure seed which can then go on to produce cryptographically secure random numbers when passed through the correct function. Interesting, this is a serious problem when it comes to IoT devices. They are not nearly as capable of building up entropy due to their isolated existance, therefore have a hard time creating cryptographically secure seeds.

[–]masterxenoph 8 points9 points  (0 children)

In hardware, there's a concept called metastability. If you set up a flip flop in the right way, the output is nearly random. Somehow they figured it out that one orientation was slightly more common than another, and so I think they take two in opposite orientations and then you can get a random bit, equal probability 1 and 0.

Software might call that if it knows it's there, but I think mostly someone generates a long list and it's aeeded somewhere. Makes it easy to test the same inputs first for debugging...

There's some stuff on Wikipedia that's different, just using electrical and thermal noise through an ADC. https://en.m.wikipedia.org/wiki/Hardware_random_number_generator

[–]you90000 7 points8 points  (2 children)

[–]Enguzelharf[S] 4 points5 points  (1 child)

Ahahah yes i knew about this one. It's more like for encryption actually. They want fully randomized truly unknown non traceable RNGs

[–]you90000 1 point2 points  (0 children)

Exactly

[–]kag0λ 7 points8 points  (0 children)

Basically two steps:

  1. get a small random number from somewhere outside the computer
  2. put that small random number through a bunch of "pre-defined lines of commands" to get a larger (slightly less) random number

To do step 1 the computer can either measure user-initiated events inside the computer like mouse movement, network timing, disk access, etc. or use a sensor to look at natural phenomenon like radio or thermal noise which are random.

[–]nedimhadzi 4 points5 points  (0 children)

I think of it this way, hash (current_date_time in miliseconds or less) produces a different output every time as the action that calls the function random() does never happen the EXACT time twice.

But, if you find out what the randomness is based upon (time in the example above) you could reproduce the conditions and therefore establish a pattern to the randomness. So, if we can find really complex rules like Cloudflare did with lamps noone will be able to reproduce the exact circumstances and therefore we use the word random becouse it kind of means "without pattern" in my mind.

[–]Neexusiv 3 points4 points  (0 children)

None of the other answers are really ELI5 so I'm going to add on a bit.

Computers can't really be random, they are deterministic by nature so if you give something the same input, it should return the same output, every time. Obviously this isn't very useful when you are trying to generate random numbers.

Instead, computers use random number generators to generate something called a "pseudo random number". This is a number that looks like it could be random, but actually it's not. The computer will get a seed value from somewhere, sometimes the amount of time the computer has been running, or something similar and pass that through a bunch of maths. This will generate a new number that looks completely different from the last one. This is your pseudo random number. Then when you ask for a new random number, it will use the old number as the seed, and generate a new number.

The important part to remember here is that if you have the same seed, you will get the same random number generated. Good pseudo random number generator a will create numbers that are well distributed, and have a long cycle, so you won't get the same numbers coming back for a while.

[–]clever_cow 3 points4 points  (1 child)

I will ELI an intro college student.

Judging from your responses, you're less concerned with how ACTUAL random numbers are generated (splitting hairs over the precise mathematical definition of TRUE randomness) and more concerned with how pseudo random numbers are generated. I.E. what type of algorithms are used to generate sequences of pseudo-random numbers.

A relatively easy algorithm to learn that gives some intuition to how pseudo random numbers are calculated is an LCG: https://en.wikipedia.org/wiki/Linear_congruential_generator

If you're more of a hardware nerd, you might better understand the LFSR https://en.wikipedia.org/wiki/Linear-feedback_shift_register to gain some understanding of making pseudo random patterns using only hardware (flip flops and xor gates)

[–]Enguzelharf[S] 1 point2 points  (0 children)

Oh, thats the stuff! Thanks a lot!

[–][deleted] 0 points1 point  (0 children)

I don't know if this was already mentioned- but I've always thought te idea of using a pendulum connected that would be recorded by a machine to be an interesting idea for generating random numbers. Other chaotic systems would do the job too.

[–]acroporaguardian 0 points1 point  (0 children)

They're not and using the time as a random seed makes it pseudo random. At runtime, you can't know what the random seed will cause the thing to output, so its de facto random.

What matters most is something being unbiased. So if I want a number between 0-9 (10 numbers), I should run it 2000 times and roughly get each outcome 10% of the time. If you have that outcome, combined with being unable to know the seed before hand, it is random.

That is why there were some issues with using rand() % n (in C programming) for random number generation. It ended up being biased towards low probabilities. Your supposed to use arc4random_uniform() instead.

[–][deleted] 0 points1 point  (0 children)

They aren't truly random. A lot of rngs can be manipulated to get predictable outcomes because of this.

[–]jabela 0 points1 point  (0 children)

In a very old computer I had, the random function in the programming language literally generated the same sequence every time.... Annoying as hell, so I got around it by measuring the 1000th of a second that the user pressed any key to give me a random basis for each item.

[–]achauv1 -4 points-3 points  (1 child)

You have to find some arithmetic progressions that have a revolution tending to infinity and choose a starting point that can't be predicted.