ELi5 , how do random number generators work?

723 views

How is it different than the program just choosing the number it wants within range?

In: 6

11 Answers

Anonymous 0 Comments

There’s basically two ways to do it.

The first method is called “pseudorandom generation”; and uses (usually) unpredictable math to generate random numbers. There’s a few ways to do this; but basically all of them involve taking a starting number, doing some math to it to give a new number, and taking just a part of the new number. For example, I take a 5-digit number, square it, drop the ones digit, and reduce it back to 5 digits; then return the ten thousands digit of the new number. If I need a 2-digit number, I do the process twice: once for the ones digit, once for the tens.

Doing this is very hard to predict – especially if sometimes I make it harder by sometimes throwing away random numbers; or by re-seeding with a function of the current time (likely using fractions of a second). But it is possible to predict – you can’t use this kind of random number generation for cryptography; and it’s usually illegal to use this kind of random number generation for online gambling.

Which brings us to “entropy generation” or “hardware generation”. This method uses some outside source of randomness: for easy randomness, things like the delay (measured in milliseconds, often only using the ones digit of milliseconds) between computer inputs can be used; but for “true” randomness, there are several companies which do things like film lava lamps, measure small differences in atmospheric conditions, or use radioactive decay – all of which are as random as you can get – to generate random numbers.

You are viewing 1 out of 11 answers, click here to view all answers.