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

1.18K 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

Random number generators in computers are usually just math. They take the last random number they generated, do some math on it, and the result is the next random number. Sometimes they’re just one big table, so they return a number from the table then return the next number next time.

The “seed” just determines the first number the algorithm does math on or where in the table it starts. So if the same algorithm gets the same seed twice, it produces the same results twice.

That DOES mean video game RNG (Random Number Generator) can be predictable. If you do some Youtube searches you can find people have written tools to exploit the RNG in lots of video games. For example, in many Pokemon games you can use tools to guarantee you catch shiny Pokemon or other rare things with a little bit of work. Speedrunners call this “RNG Manipulation”.

The way games that REALLY don’t want you predicting their RNG work is usually just to sample a TON of random numbers so it’s very hard for the player to understand “where” the RNG is. For example, the Pokemon tricks I mentioned can be tough to pull off because the game often “rolls” a new random number every frame, so you don’t just have to do specific things to get the RNG in the state you want, you also have to push buttons on EXACTLY the right frame. Gambling games tend to pick new seeds very often and do tricks like Pokemon to make it harder to guess the state of the RNG.

REALLY important computer programs don’t use this kind of math to get random numbers. They use fancy hardware that connects to real-world objects to get their random data. The classical example is “being hooked up to a source of radiation and measuring its fluctuations”, as that basically behaves randomly. The *funny* classical example is “a webcam pointed at a lava lamp”. This stuff is expensive and fiddly, so consoles use math because it’s “good enough”.

Circling back: games that let you use “seeds” like this INTEND for you to be able to play the same game as a friend, so instead of trying to PREVENT you from guessing RNG state they give you a box to control it. When you enter a seed, some or all of the random numbers will be predictable, so two people who do the same things will have the same “luck”.

In Minecraft, that’s how terrain generation works. How does it decide what biome to generate? Random numbers. How does it decide where to put caves? Random numbers. How does it decide where to generate the Stronghold? Random numbers. The game has been built to do all of that stuff in the same order every time, so if two people use the same seed, they’ll have the same world.

The fun part of that is it sort of works like a really good ZIP file. If you want to “share” a cool world that you haven’t built anything in yet with a friend, you get to send a really small number instead of a big file.

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