how do random numbers on computers work?

1.45K views

For example, is there a formula for a random number?

In: 47

75 Answers

Anonymous 0 Comments

aside from many of the answers for modern day methods, there was a retro game development video I watched which went over how they used to get random numbers.

first was obviously, use maths or statistics but this was expensive. second was to use the current frame which in those days was not guaranteed as frames were computed last. the last one, most interestingly, used in I believe ff4 (made by one guy) literally sequentially went through a static set of results.

Anonymous 0 Comments

They don’t. Computers can’t be random. But they can be pseudorandom. So random enough to look random to a casual observer. Generally they do this by incorporating something non-computery, like a human.

So for example, let’s say you need a number from 1-100 at random. What it could do is be constantly counting from 1-100 in the background. When you ask it for a number it stops and gives you whatever it’s landed on. So to a human it looks random. Obviously there are other methods, that’s one hypothetical example. A lot of devices use the device’s clock to get something random. That’s just one way you could use human interaction to have a computer generate a “random” number.

Because computers aren’t random, if you know exactly what they’re doing, they can be manipulated. High-level Pokémon speedrunners actually learn how to manipulate the game’s randomness to get the results they want.

Anonymous 0 Comments

The first (and easiest to understand) method of generating random numbers did indeed use a formula. Given the previously generated number `x`, a random seed `c`, a multiplier `a`, and a modulus m, you can compute a pseudorandom number as `(a * x + c) mod m`, where mod m means “divide by m and take the remainder”. See [https://en.wikipedia.org/wiki/Linear_congruential_generator](https://en.wikipedia.org/wiki/Linear_congruential_generator) for more details

Nowadays, we have more complex algorithms, but they’re a lot harder to understand without going really in depth. If you’re curious, wikipedia also has good explanations of them: [https://en.wikipedia.org/wiki/Mersenne_Twister](https://en.wikipedia.org/wiki/Mersenne_Twister), [https://en.wikipedia.org/wiki/Xorshift](https://en.wikipedia.org/wiki/Xorshift), [https://en.wikipedia.org/wiki/Well_equidistributed_long-period_linear](https://en.wikipedia.org/wiki/Well_equidistributed_long-period_linear)

Anonymous 0 Comments

aside from many of the answers for modern day methods, there was a retro game development video I watched which went over how they used to get random numbers.

first was obviously, use maths or statistics but this was expensive. second was to use the current frame which in those days was not guaranteed as frames were computed last. the last one, most interestingly, used in I believe ff4 (made by one guy) literally sequentially went through a static set of results.

Anonymous 0 Comments

They don’t. Computers can’t be random. But they can be pseudorandom. So random enough to look random to a casual observer. Generally they do this by incorporating something non-computery, like a human.

So for example, let’s say you need a number from 1-100 at random. What it could do is be constantly counting from 1-100 in the background. When you ask it for a number it stops and gives you whatever it’s landed on. So to a human it looks random. Obviously there are other methods, that’s one hypothetical example. A lot of devices use the device’s clock to get something random. That’s just one way you could use human interaction to have a computer generate a “random” number.

Because computers aren’t random, if you know exactly what they’re doing, they can be manipulated. High-level Pokémon speedrunners actually learn how to manipulate the game’s randomness to get the results they want.

Anonymous 0 Comments

They don’t. Computers can’t be random. But they can be pseudorandom. So random enough to look random to a casual observer. Generally they do this by incorporating something non-computery, like a human.

So for example, let’s say you need a number from 1-100 at random. What it could do is be constantly counting from 1-100 in the background. When you ask it for a number it stops and gives you whatever it’s landed on. So to a human it looks random. Obviously there are other methods, that’s one hypothetical example. A lot of devices use the device’s clock to get something random. That’s just one way you could use human interaction to have a computer generate a “random” number.

Because computers aren’t random, if you know exactly what they’re doing, they can be manipulated. High-level Pokémon speedrunners actually learn how to manipulate the game’s randomness to get the results they want.

Anonymous 0 Comments

In the context of most computing applications, “random” is just another word for “unpredictable”. You just want to generate a number that can’t be easily predicted by anyone. Of course, there are different levels of unpredictability. If you simply use a mathematical formula that generates a chaotic series of numbers, then all someone would need is that formula to predict the numbers that are to be generated. If instead you use the 4th decimal point of the temperature of your CPU in Kelvin, divided by the ASCII code for the first character of Elon Musk’s latest tweet, multiplied by the distance between two GPS-tagged blue whales, divided by the real-time airspeed velocity of an unladen swallow… well, you’ll get a much less predictable number.

But these are all still considered pseudo-random, because with enough information, you could still predict the next number. A truly random number would be one that no one could ever predict, no matter how much information they had about the current state of the universe. Basically, a number that God can’t predict. Determining whether it’s possible to generate a truly random number becomes more of a philosophical argument about determinism than a mathematical problem.

But for computer applications, as long as a number is sufficiently unpredictable for its application, then it’s considered random “enough”. Obviously, if you’re generating encryption keys for top secret military communications, you’ll probably want a less predictable random number generator than if you’re generating random numbers for a freeware slot machine app.

Anonymous 0 Comments

In the context of most computing applications, “random” is just another word for “unpredictable”. You just want to generate a number that can’t be easily predicted by anyone. Of course, there are different levels of unpredictability. If you simply use a mathematical formula that generates a chaotic series of numbers, then all someone would need is that formula to predict the numbers that are to be generated. If instead you use the 4th decimal point of the temperature of your CPU in Kelvin, divided by the ASCII code for the first character of Elon Musk’s latest tweet, multiplied by the distance between two GPS-tagged blue whales, divided by the real-time airspeed velocity of an unladen swallow… well, you’ll get a much less predictable number.

But these are all still considered pseudo-random, because with enough information, you could still predict the next number. A truly random number would be one that no one could ever predict, no matter how much information they had about the current state of the universe. Basically, a number that God can’t predict. Determining whether it’s possible to generate a truly random number becomes more of a philosophical argument about determinism than a mathematical problem.

But for computer applications, as long as a number is sufficiently unpredictable for its application, then it’s considered random “enough”. Obviously, if you’re generating encryption keys for top secret military communications, you’ll probably want a less predictable random number generator than if you’re generating random numbers for a freeware slot machine app.

Anonymous 0 Comments

Yes there are formulas for (pseudo)random numbers. Simplest example is https://en.m.wikipedia.org/wiki/Logistic_map

Anonymous 0 Comments

In the context of most computing applications, “random” is just another word for “unpredictable”. You just want to generate a number that can’t be easily predicted by anyone. Of course, there are different levels of unpredictability. If you simply use a mathematical formula that generates a chaotic series of numbers, then all someone would need is that formula to predict the numbers that are to be generated. If instead you use the 4th decimal point of the temperature of your CPU in Kelvin, divided by the ASCII code for the first character of Elon Musk’s latest tweet, multiplied by the distance between two GPS-tagged blue whales, divided by the real-time airspeed velocity of an unladen swallow… well, you’ll get a much less predictable number.

But these are all still considered pseudo-random, because with enough information, you could still predict the next number. A truly random number would be one that no one could ever predict, no matter how much information they had about the current state of the universe. Basically, a number that God can’t predict. Determining whether it’s possible to generate a truly random number becomes more of a philosophical argument about determinism than a mathematical problem.

But for computer applications, as long as a number is sufficiently unpredictable for its application, then it’s considered random “enough”. Obviously, if you’re generating encryption keys for top secret military communications, you’ll probably want a less predictable random number generator than if you’re generating random numbers for a freeware slot machine app.