### Computers are deterministic > In mathematics, computer science and physics, a deterministic system is a system in which **no randomness is involved** in the development of future states of the system. A deterministic model will thus **always produce the same output** from a given starting condition or initial state. > <sub>[Deterministic Systems][1] - Wikipedia</sub> Think of a computer like a cook, who has been handed a recipe (a program) to bake a cake. Computers **do not deviate** from the instructions (input) in a program, meaning that each cake they bake (output) will be identical. So how do programs (including games) implement randomness? Kinda like this: [![xkcd 221: Random Number][2]][2] <sub>[Comic #221: Random Number][3] - xkcd</sub> A mathematical formula is used to "fake" randomness. This is known as a **Pseudorandom Number Generator** (PRNG), often abbreviated to just Random Number Generator (RNG). The problem is, being a mathematical formula - if you give it the same input value, you'll get the same output value. So we're left with a problem: ### What is the initial starting value? This is where the "seed" gets its name. It's a **seed value**, a number used to start the random number generator, so that it may generate future pseudo-random numbers. In most games, the seed is determined automatically using a few tricks, like deriving a value from the system clock, or the number of frames generated before user input. But this is also why clock manipulation or frame-counting are popular tactics in speedrunning circles - because they can take the "randomness" out of certain actions, to guarantee a more perfect run. In other games like Minecraft which relies heavily on randomness for it's world generation, they allow you to manually specify a seed to get the "same" world generation. --- ### Math/Comp-Sci crash course: Just for fun, let's look at a working example of a basic pseudorandom number generator: ``` Next_Value = (Multiplier * Current_Value + Increment) % Modulus ``` The Modulo `%` operator gives us the remainder after division by the Modulus, e.g if `10 / 8 = 1 r2`, then `10 % 8 = 2`. So let's set some values in the formula, and generate numbers between 1 and 100: ``` Next_Value = (7 * Current_Value + 5) % 101 ``` We need to seed `Current_Value` with something, so let's do a seed of **1**: | Current Value | Formula | Next Value | |---------------|--------------------|------------| | 1 (Seed) | (7 * 1 + 5) % 101 | 12 | | 12 | (7 * 12 + 5) % 101 | 89 | | 89 | (7 * 89 + 5) % 101 | 22 | | 22 | (7 * 22 + 5) % 101 | 58 | and now, let's try a seed of **42** | Current Value | Formula | Next Value | |---------------|--------------------|------------| | 42 (Seed) | (7 * 42 + 5) % 101 | 97 | | 97 | (7 * 97 + 5) % 101 | 78 | | 78 | (7 * 78 + 5) % 101 | 46 | | 46 | (7 * 46 + 5) % 101 | 24 | As you can see, we're getting some "fake" random numbers, based off a seed value! Pretty cool, right? [1]: https://en.wikipedia.org/wiki/Deterministic_system [2]: https://i.sstatic.net/0bhcfStC.png [3]: https://xkcd.com/221/