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

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)

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