How do random number generators work?

271 views

How do random number generators work?

In: 119

10 Answers

Anonymous 0 Comments

As a specific example of how a random number generator might generate a single digit, it would use a *modulo* function. It’s essentially the same thing like what you probably learned in elementary school when a number is not perfectly divisible by another, and you have a “remainder”. Like, 102/5 is 20.4, or you could say 20 with 2 remaining (because 2 is not divisible by 5 without decimals). You would say this is as 102 *mod* 5 = 2.

So, grab a number that the computer has easy access to like the current time in milliseconds: 1652012941065. Grab another number like, I dunno, the CPU core temperature: 48. Take the last digit of that, which is 8, and do the first number *mod* the second number: 1652012941065 mod 8, which a calculator tells me is 1.

The odds of two number generators having the same core temperature are pretty decent. The odds of two number generators performing the check at the exact same same time are not *great* but not impossible. The odds of both happening at the same time are slim enough that it probably won’t happen much.

Of course, for security purposes, you’d want a much larger, longer number. So the process can be more complicated like multiplying the current millisecond time by a CPU clock cycle and then again by some other seed number and do *mod* of another big number made similarly.

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