There are different kinds of random number generators, but most modern ones sort of work on similar principles. Note that, to be pedantic, if we’re talking about computer random number generators they are usually “Psuedorandom Number Generators”. This is because they all have characteristics that make it possible to predict their sequence if you have enough information. More on this at the end.
In older, more limited games, the game was usually updating itself every frame in a loop. It might keep a “frame counter” that is what it says: it starts at 0, is set to 1 on the first frame, then 2, then 3, etc. Some random number generators would base their random number on that frame counter. For most players this was fine, but for speedrunning types this is exploitable!
The more complicated ones revolve around some mathematical function. This function takes some numbers as inputs and spits out other numbers. If you feed the numbers you get back into it, you get different numbers. If you do this long enough, you’ll see the entire sequence repeat. If you start with different numbers, you’ll start somewhere in the ‘middle’ of that sequence. It will repeat after the same number of tries, but the sequence will look different since you “started” in a different place. Logically speaking, it’s like all of the numbers are in a table and the numbers you start with determine where you start. After that, you keep getting the “next” number in the table until you reach the end and start over.
To pick the “start” numbers, a lot of programs use the computer’s current time. That guarantees if you start the same program at different times you’ll see “random” events happen in a different order. But even *that* is exploitable by very determined people, so the random number generators for “important” things like online casinos use more complicated techniques to pick their starting numbers, like looking in random parts of computer memory and using the values there. Some encryption programs ask you to move the mouse and type for a while before they start work: they’re using your keystrokes and mouse movements to pick the starting numbers in a way that is less predictable than just using the time.
Even then, if enough numbers are generated the sequence repeats. So really fancy cases like online casinos will periodically “reseed” their generators by picking new “start” numbers. This is not unlike shuffling decks more frequently to try and thwart card counters.
There are also some “true random number generators” that are completely not predictable but they are too complex and expensive for most people. They rely on real-world phenomena like “When does this sample of a radioactive material emit some energy?” to pick numbers. There’s even an interesting project that pointed a camera at a lava lamp for a source of true randomness! Since these tend to involve cameras or other fancy sensors, they aren’t used much outside of laboratories.
Latest Answers