DEV Community

Discussion on: Explain the challenge of generating random numbers like I'm five

Collapse
 
yechielk profile image
Yechiel Kalmenson • Edited

In order to explain that we have to understand what computers are good at, and what they're bad at.

Computers are good at following instructions. Computers are bad at making things up.

Computers need clear, unambiguous instructions, and "make up a random number" is very ambiguous. Which number? How should I find it? How do I know if it's random? etc.

What we can do is give a computer a set of instructions to do some complicated math procedures and arrive at a seemingly random number (take this really large number, multiply it by another large number, divide it by this third number, etc, etc). Butthe problem with giving a computer a set of instructions is that anyone who follows the same instructions will get the same number, which is why we say it's only pseudo-random.

In order to get a truly random number we can use an outside input. You remember part of the instructions was to multiply some large number? What if we chose that number not by telling the computer directly, but by using a number from a source that changes often and chaotically? For example, we could look at the humidity level in Croatia, the position of the DOW, even the color of a lava lamp at a given moment.

By adding in a random chaotic input we can ensure that even if someone else follows the exact same set of instructions as you, they will always get a different number.

Collapse
 
etienneburdet profile image
Etienne Burdet

"Computers are good at following instructions. Computers are bad at making things up."
This!💯

Collapse
 
peter profile image
Peter Kim Frank

This is brilliant. Thanks so much, Yechiel!

Collapse
 
yechielk profile image
Yechiel Kalmenson

Thanks!