r/howdidtheycodeit • u/HugoNikanor • Aug 16 '23
How does games like Minecraft ensure consistent world generation?
I know how computers generate "random" numbers, and what seeds are. What I don't understand is how, for example Minecraft, can give you the same world from the same seed each time, no matter which order you generate it in.
How does that work?
14
Upvotes
4
u/NoteBlock08 Aug 16 '23
Look up Perlin Noise. Random number generators can work in a lot more ways than just sequentially, which it sounds like is what you're thinking of. For more complicated random generation like world-gen they can take plenty of other variables besides/other than just a seed and how many times it's been called before.
37
u/ThomasHiatt Aug 16 '23
You write a function that takes (x, y, z) coordinates and a seed as input and returns a value computed from that input the same way every time. In the case of Minecraft it uses Perlin noise. This is a good video that explains a lot of it, I got a few insights from it even though I already knew a lot about procedural generation https://www.youtube.com/watch?v=ob3VwY4JyzE
3
u/Denaton_ Aug 17 '23
Nothing is random, it may only look random.
https://en.wikipedia.org/wiki/Random_seed
16
u/Jumpy_Quantity_2148 Aug 16 '23
Henrik Kniberg from Mojang has a great explanation here: https://youtu.be/ob3VwY4JyzE
21
u/echoAnother Aug 16 '23
Then you don't know what a seed is.
A seeded RNG (or P(seudo)RNG) is not random at all. It will produce always the same cyclic sequence of numbers from the seed. Usually they provide it in a uniform distribution.
However the generation of the seed is actually random.
As a fun fact, for most PRNG (I don't dare to say all), a slice [n:m] of the sequence for a determined seed, will be equal to a slice [x+n:x+m] of the sequence of any other seed.
2
u/Katniss218 Aug 17 '23
Look up Noise functions and hash functions in.
Hash functions are used to map an xyz coordinate triplet to a random-looking value typically in - 1..1 or 0..1
They're also used a lot in graphics and shaders, when you need a random value (gpus aren't suited for full prngs like MT)