how do “seeds” work in video games such as Minecraft?

1.17K viewsOtherTechnology

For example, how does an infinitely randomized world like Minecraft manage to generate me an identical world to my friend with just a handful of numbers that they send me?

In: Technology

23 Answers

Anonymous 0 Comments

Ooh I have such a nice example for that. Imagine a racing video game where the race track can be generated using a seed. For the sake of this example this will be an infinite race track and not a closed circuit. Now the video game has a set of track pieces that can be assembled together (a zig zag track piece, a loop track piece, etc, you get the idea).

Now, imagine you have 10 of those track pieces, each numbered from 0 to 9. When you provide a seed, it will first calculate a modulo 10 of this seed. For example, let’s use 14 as our seed: 14 mod 10 = 4. For the first track piece, you’ll select the one that is numbered 4. Modulo is a trick used to ensure that the value used will be always between 0 and 9, hence why the tracks were numbered that way.

Enter the random number generator function. This is a function that takes a number as input, then outputs a completely nonsensical number as output. Rng functions come in all shapes and sizes. The crazier the calculation is, the better the rng function. For example it can be something like f(x) = 100 * sin(x^123) + log(x^456).

Now we plug our seed in this function and we’ll get a completely different number. We’ll apply the same mod 10 calculation then select the track piece based on the result of the modulo. This track piece will be attached to the first track piece.

I think you can see where I’m going that, we’ll keep repeating the same thing over and over again indefinitely to generate an infinite race track.

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