You can design a box that takes a bunch of bits as input, and runs a calculation that thoroughly “mixes up the bits.”
The box’s output “looks random.” For example:
– If you feed the box a 1, you get 815965.
– If you feed the box a 2, you get 462141.
– If you feed the box a 3, you get 122526.
– If you feed the box a 4, you get 007855.
– If you feed the box a 5, you get 095046.
– If you feed the box a 6, you get 955227.
There’s no obvious rhyme or reason to the output, it’s a bunch of random 6-digit numbers.
The details of how the box works internally could be a whole nother post. What’s important is that those internal workings are a computer program that always does the same thing if you give it the same input. So:
– If you feed the box a 1, you get 815965.
– If you feed the box a 1 again, you get 815965.
– If you feed the box a 1 a third time, you get 815965.
Different inputs? Random. Same input? Same output.
You can use the output numbers to make various decisions about the world. For example the first two numbers were 815965 and 462141. Okay, we’ll make point (815, 462) on our 1000×1000 world grid to be the location of some ruins.
Let’s say there’s a 20% chance for plains, a 30% chance for forest, and a 50% chance for mountains. So if our next number is between 000000 and 199999 it will be a plains, if it’s between 200000 and 499999 it will be a forest, if it’s between 500000 and 999999 it will be mountains.
The next number is actually 122526 so our ruin is on a plains.
We don’t want one isolated plains tile to be jumbled into a bunch of mountain and forest tiles. We want our ruins to be in the middle of a plains patch. So we use more random numbers to decide the size and shape of the patch.
There could be thousands or millions of random numbers involved in generating the whole world.
So where does the seed come into the process?
Well we started our random sequence by inputting 1 to the random number generator function. On the game setup screen we add a box where the user can enter a seed, and then if the user enters say 5678, instead of feeding the box 1, 2, 3, … we instead feed the box 5678000001, 5678000002, 5678000003, …
Feeding the box a different sequence will give you different results. So instead of our ruins being located at (815, 462) in a 12-tile patch of plains, the box will give us different output. Meaning, we’ll decide to put the ruins at (337, 406) in a 17-tile patch of mountains with a different shape.
If the user gives the game the same seed, all the rolls are the same. When we run the world generation process again with the same seed we used before, we’ll put the ruins at the same place, pick the same terrain, pick the same size and shape for the terrain patch, and so on. Every choice will be the same, so an identical world will be created.
The random generation process only gives us the base world. We have to use a separate system to keep track of modifications the player’s made to the world, and apply them in a separate step.
Latest Answers