# Can anyone explain to math-dumb people like me how computers can generate random numbers?

Asked by

Kraigmo (

7802)
September 16th, 2010

It’s not important to my life, but it does confuse my mind, so I’d kind of like to know.

How do computers make a random number? They must do that all the time, for video games to work, right?

And the fact the computer doesn’t choose the same number each time, or same sequence either…. that seems impossible to me.

So how does that happen? And please explain it simply as possible, using analogies if they work.

Observing members:
0
Composing members:
0
## 9 Answers

Random numbers generated by computers aren’t truly random (they couldn’t be), but they’re effectively random for most purposes.

@chocolatechip One of those “math-dumb” people, here. What do you mean they couldn’t be truly random?

Computers generate what are called pseudo-random numbers. They are sets of numbers that exhibit similar properties to random numbers but they are not truly random. These sets of numbers are finite (limited by the memory of the computer) and therefore can repeat (after a very long time) and cause problems depending on your application (i.e. it’s not actually ideal for cryptography).

Pseudo-random number generators usually take a seed or starting value to begin generating pseudo-random numbers. Quite often the current time (down to the millisecond) is used (and sometimes combined with the network address of the computer).

There are many algorithms for pseudo-random number generation so in this case it really depends. The gist of it is it does some work—often utilizing the modulo operation from what I can tell—on the last value to create the new one. That work varies from algorithm to algorithm. The Yarrow algorithm is a decent example (although ironically it’s no longer considered secure and has documented flaws). It was used for /dev/random on *nix-based operating systems.

What’s great about pseudo-random number generators is they are fast. Physical random number generators can be slow although there’s some work being down on that. A couple more advanced methods of seeding a pseudo-random number generator are to turn a series of mouse movements or a photo or video frame into a number. Asking a human for a starting value would be crap since everyone picks fucking 17 or 37—huge pet peeve of mine, especially in movies.

Great question & great answer by @timtrueman.

Pseudo-random numbers are based on non-linear systems that bear some relation to so-called chaotic systems. They have a curious combination of properties—being both deterministic and unpredictable. After all, a computer follows a pre-programmed sequence of rigid rules, hence deterministic. Give it the same input and you will always get the same output. It is indeed a very thoughtful question.

But the results of these algorithms are unpredictable in the sense that slightly different seeds (input values) will generate wildly different output numbers, in such a way that the outputs have the same statistical properties as random numbers—hence pseudo-random. Typically the computer uses the previous output value to re-seed the next input. In this manner new pseudo-random numbers are generated each time. Theoretically, however, the pseudo-random sequence should repeat after a finite time.

For truly random numbers, you could use a measurement based on radioactive decay to generate an input. In practice this is rarely done.

In one of my processes I use the least significant three digits of my 40 MHz clock/counter. The interrupt request is tied to an external physical process so there’s no cross talk.

Yeah, it’s actually not possible to generate truly random numbers using just software. As @timtrueman pointed out, there are some very effective algorithms, and by mixing in the system clock, pseudo-random is close enough for most purposes.

For special applications that require totally random numbers, you generally have to rely upon some kind of physical/natural phenomenon that’s complex enough to be considered actually random. (Rolling dice,flipping a coin, etc.) Though it could be argued that even those aren’t *actually* random, they are just practically random to do incalculable complexity. For computers, you can buy special hardware that gives you similar behavior.

It’s actually a very deep question.

This is fascinating. I didn’t know any of this. I am authentically math-dumb, as the OP put it. Math is like a foreign language to me, not something I’ve ever been able to wrap my head around. I really appreciate that this question was asked and the answers that were given… I feel like I’ve learned a lot from this thread.

Right, for dumb people.

Instead of picking a number that is a simple product of the number you began with (like 1,2,3 just being +1 each time), you just make it really really complicated until you’ve lost any predictability. (like 1,-76,-50,933 is still just done by taking some numbers and throwing them in a blender)

## Answer this question