Simples RNG works as follows:
1. take a number between 0 and 1, with lots of decimals.
2. Multiply by a really large number
3. Keep the decimals, drop the integer part (e.g. 123.4567 becomes 0.4567)
4. You have another number between 0 and 1, and there is no easy way to predict its range if number in step 2 was indeed large.
5. if you want more random numbers, take the number from step 4 and use it to repeat steps 2-3.
NUmber from step 1 is the “seed”. Same seed means same sequence of “random” numbers. Which is useful for debugging. For a truly random choice of seed, take system clock and use it decimals from seconds counter.
Typically by using a pseudo-random number from a seed. So imagine you start with a seed something like the current second-minute-hour-day-month-year so a number like 20220708155533. They then do a series or predetermined math calculations (like say x73, -1234567890, x123, +9874561230, x258369, -7777777777) then take the digit that is in the 10000 digit as the random number.
Computers have a very hard time generating actual random information. To generate the entropy (chaos) needed to get actual random information, it is often necessary to use an external source of random data.
Short of that, computers can use something called a pseudorandom number, which is not truly random- but is random enough for many purposes, or within a certain context. For example, using the number of microseconds elapsed since a specific time together with information about how a user moves a mouse is one way.
Truly random data is frequently created by using things like weather patterns, radioactive decay, or- my favorite- pointing a camera at a wall covered with lava lamps and putting the resulting picture through an algorithm to create random numbers.
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.
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.
Firstofall, let me just tell you that most computers do not possess true RNG. This is because the number used is generated algorithmically. Now, an algorithm has a precise definition, and one of the points on this definition is that it is deterministic, in other words, if you run it multiple times with the same input, the output must be the same each time.
As for these computers, which use so called pseudo-random numbers, they usually take a lot of different variables on your computer to generate numbers that aren’t random, but close enough to random for most purposes. This could include, for example, the last 25 keystrokes you made before generation, your system time, the current runtime (that is time since bootup) of your computer, and a whole host of other numbers.
Now, thing with this is that, again, these numbers are only close enough to random; If someone knew all the variables in the calculation, and knew exactly what the values of these variables were when you ran the random number generator, they could theoretically run the same algorithm to figure the number out, which is why these aren’t used for, for instance, online encryption.
A video game, however, is likely to use this sort of number generator, because for the purposes of a video game, close enough for it to feel random when it really isn’t is good enough; However, you might have heard speedrunners use the term “RNG manipulation”. This is exactly what it sounds like.
If you knew every variable in the games random number generator, you could, theoretically, purposefully make inputs to make said random numbers occur in your favour, thus saving time. This is possible because the algorithm is just that; it generates a number that is close enough to random for you to think it is, but at the end of the day, it is still an algorithm, and therefore deterministic.
The program cannot choose what it wants, because the computer doesn’t know what it means. “Choose what you want” is just not in the list of commands it can do. So you need to “explain” it to the computer using only things it can understand.
Moreover, there are usually some requirements on what exactly should be chosen. For example, the program can always “want’ to choose 4. But you would probably say, that a stream of 4s are not really that random. You probably want all numbers to appear equally likely. You may want pairs or triplets of numbers to be as random as singles, or you may not. You might want next number to be very hard to predict, or you might not. You might want a sequence to either be repeatable, or as unrepeatable as possible.
Depending on your needs, there are different programs that produce different random sequences:
* *Pseudo-random* generators are basically a big looping sequence of numbers, generated by some formula. They are repeatable: if you know the initial position, you can “play back” the same numbers. They are also might be predicted, if the someone guesses that initial position. But they are fast, and can have good statistics.
* *True random* generators produce numbers from some real unpredictable process. They cannot be predicted, and cannot be repeated. But real random processes are rarely fast, and rarely “fair” (which means, that different results can have unequal probability). They can also be manipulated, by influencing the “random box” somehow. They are used for random initial values for pseudo-random generators.
* *Cryptographic* generators are very hard to predict by observing only inputs. They are used for ciphering and security. They can be both pseudo-random and true random.
There’s pseudo-random numbers, aka a computer program starting from an initial seed (usually, the time indicated by the system clock). This seed works as “source of randomness” Basically, the program takes the seed as an input, does some calculation and outputs a number that will, for some purposes, be random enough to be used. There are other sources of randomness, like using the sound picked up by the computer microphone.
For some applications where it is of critical importance that the pseudo-random numbers cannot be guessed in advance, not all sources of randomness are suitable, because some are predictable. For example in online betting games with money at stake, you wouldn’t want a player to be able to predict which random numbers are going to come up, based on which ones already came up during the course of a game. The same kind of problem might arise as well in some scientific applications, for example maybe the Monte-Carlo algorithm (an algorithm that finds zeros of a function by resorting to randomness).
Hence, for such applications, you need to make sure that your source of randomness is suitable. Suitable might mean “one cannot predict which number will come up next” for online betting games”, or it might mean that the statistical distribution of a large amount of these numbers, follow some properties that are convenient for scientific applications.
There are sources of randomness that are, from my understanding, better than the basic “microphone sound” or “system clock” ones. One example is [random.org](https://random.org), a website that gives you pseudo-random numbers that it has generated using atmospheric noise as a source of randomness. Interestingly enough, this website mentions on its main page that its pseudo-random numbers are being used for lotteries, online games, and scientific applications.
There’s pseudo-random numbers, aka a computer program starting from an initial seed (usually, the time indicated by the system clock). This seed works as “source of randomness” Basically, the program takes the seed as an input, does some calculation and outputs a number that will, for some purposes, be random enough to be used. There are other sources of randomness, like using the sound picked up by the computer microphone.
For some applications where it is of critical importance that the pseudo-random numbers cannot be guessed in advance, not all sources of randomness are suitable, because some are predictable. For example in online betting games with money at stake, you wouldn’t want a player to be able to predict which random numbers are going to come up, based on which ones already came up during the course of a game. The same kind of problem might arise as well in some scientific applications, for example maybe the Monte-Carlo algorithm (an algorithm that finds zeros of a function by resorting to randomness).
Hence, for such applications, you need to make sure that your source of randomness is suitable. Suitable might mean “one cannot predict which number will come up next” for online betting games”, or it might mean that the statistical distribution of a large amount of these numbers, follow some properties that are convenient for scientific applications.
There are sources of randomness that are, from my understanding, better than the basic “microphone sound” or “system clock” ones. One example is [random.org](https://random.org), a website that gives you pseudo-random numbers that it has generated using atmospheric noise as a source of randomness. Interestingly enough, this website mentions on its main page that its pseudo-random numbers are being used for lotteries, online games, and scientific applications.
There’s pseudo-random numbers, aka a computer program starting from an initial seed (usually, the time indicated by the system clock). This seed works as “source of randomness” Basically, the program takes the seed as an input, does some calculation and outputs a number that will, for some purposes, be random enough to be used. There are other sources of randomness, like using the sound picked up by the computer microphone.
For some applications where it is of critical importance that the pseudo-random numbers cannot be guessed in advance, not all sources of randomness are suitable, because some are predictable. For example in online betting games with money at stake, you wouldn’t want a player to be able to predict which random numbers are going to come up, based on which ones already came up during the course of a game. The same kind of problem might arise as well in some scientific applications, for example maybe the Monte-Carlo algorithm (an algorithm that finds zeros of a function by resorting to randomness).
Hence, for such applications, you need to make sure that your source of randomness is suitable. Suitable might mean “one cannot predict which number will come up next” for online betting games”, or it might mean that the statistical distribution of a large amount of these numbers, follow some properties that are convenient for scientific applications.
There are sources of randomness that are, from my understanding, better than the basic “microphone sound” or “system clock” ones. One example is [random.org](https://random.org), a website that gives you pseudo-random numbers that it has generated using atmospheric noise as a source of randomness. Interestingly enough, this website mentions on its main page that its pseudo-random numbers are being used for lotteries, online games, and scientific applications.
Latest Answers