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

1.14K 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 generation isn’t truly random. It uses a “seed” to start the random generator. Each seed will have its own unique output

If subsequent generation is deterministic (meaning it generates things in the same order), then the random numbers will come out the same and result in the same outcome

To get “random”, the initial seed uses something such as current time, random static picked up by a microphone, etc

Anonymous 0 Comments

It’s not random it’s just REALLY complicated basically. If you do a random assortment of 20 numbers there are over a million possibilities and it “randomly” assigns you one of those strings of numbers

It then uses those numbers to plug into an equation. Think of if it was 4x-3. Then if it produces a number between an and b it makes it a certain biome and then if the last two digits are between c and d it puts a structure in this spot. Thats a huge over simplification but basically it plugs this number into a bunch of equations and one small part of each equation decides each and every block in the world.

It also takes into account a lot of “procedure” which basically means it’s not actually measuring it block by block but more so it says ok this biome is here. Now this biome stops on this block. Now here there is a cave. And then in the block next to where the cave starts it plugs in the number to decide if the cave keeps going or if it turns and stuff like that. Each block is related to the ones next to it to create consistent structures like caves that seem kinda random but at the same time planned and connected

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.

Anonymous 0 Comments

Computers are actually quite bad at generating random numbers. Instead, they use math to generate “pseudo-random” numbers that are “random enough” for most purposes. A simple version of this might be “ok, it’s 11:04 am, so to generate “random” numbers, start with the 11th digit of pi and take every 4th digit from there.” Without knowing the math used and the starting value (seed), the results appear random to us. But if you input the same “seed”, you’ll get the exact same results. This is how games like minecraft work – if you don’t give a seed they pick/generate one (often based on the current time), kick off the pseudo-random number generator, and generate the world. The ability to generate the same world from the seed is a consequence of that, and useful for testing (so you can recreate the exact same conditions), and some players tend to like it as well, so they make it easy to access and set the “world generation seed”.

Anonymous 0 Comments

All “random” numbers generated by computers aren’t actually random. In reality they form a repeating sequence of “pseudo-random numbers”, which can be longer or shorter, depending on the quality of the number generator.

For example, the PRNG in the 8-bit Sinclair ZX Spectrum computer has a period of 65537, which is 1+2^16. This means that after that many numbers generated, they will always repeat themselves, until you give it a new seed.

Anonymous 0 Comments

A very similar question was asked [two months ago](https://www.reddit.com/r/explainlikeimfive/comments/1bb25qf/comment/ku70q1z/), and once again most people are giving the wrong answer. Minecraft worlds are NOT randomly generated. They’re procedurally generated from a (pseudo) random starting point, the seed.

Here’s a copy and paste of part of my answer to the other post:

How does a seed get turned into a world? Well, I don’t know the exact method Minecraft uses, but imagine a simplified version where you take a deck of cards and use it to create a map grid. Take two factory fresh decks, all the cards in the same order. If you lay them out in a grid the same way, you’ll end up with two identical “maps”. Shuffle one deck, then lay the grid out again, and you’ll get a random map. Copy the shuffled order to the second deck, and follow the procedure of laying out the cards, and you’ll get the same “random” map.

The card order is analogous to the seed number. Input the number, put it through a mathematical procedure, and it turns out a consistent result. Laying cards out in a grid is a simple mathematical procedure, but you could also do more complicated procedures. To continue the card map analogy, say that every four cards you not only put down the card, but also put a poker chip on the card, of a value determined by the surrounding cards, and then used the resulting poker chip values to put down pretzels at corresponding places in the grid, and then added up the value of each row of cards and… You could make the procedure as complicated as you want, but as long as you follow the procedure it will result in the same map for any given seed, while still having a huge number of possible maps because of how many different orders the cards can start in.

Whatever mathematical procedures Minecraft is applying to the seed are lot more complicated, but the same general principle applies. If you perform the same math on the same starting number, you’ll get the same results.

Anonymous 0 Comments

The game does math whenever it needs to place an object in the world. The seed is one part of that math, and the only thing that changes. If you don’t specify a seed, one is chosen at random, but if you enter one, that number goes into all the formulas. Since all the inputs are the same, the output will be as well.

Anonymous 0 Comments

True randomness doesn’t really happen. You can roll a pair of dice and the result looks random, but if you start with the same hand position and throw them in the exact same way, you will find that the dice end up with the same result.

Computers are very good at perfectly doing things the exact same way multiple times in a row, so if you watch it generate some random numbers and then start the program over, you can actually predict what numbers its going to generate.

A “seed” is a sort of intentional offset to mess with the initial starting point of the randomness simulation. In the dice metaphor, it’s like telling the program to start with their hand in a specific position before rolling. It’s still not technically random, but nobody can predict the results anymore unless they know the seed. A lot of gambling-type simulators use a seed based on current day/time so that it’s super hard to force seed reuse (and therefore cheat the system), but something like generating a minecraft world only needs to look random enough, but there’s no problem if people decide they want to go back to another world they’ve seen before, so they decided to just tell you the starting position of the randomizer.

Anonymous 0 Comments

The way I explained this to a friend the other day is, when minecraft is generating a world, the placement of everything, is basically a bunch of coin flips or dice rolls. This mountain here is this tall based on a dice roll. This diamond being in this position or not, is a coin flip.

But, computers can’t flip coins or roll dice, they use math to simulate random numbers. And a “seed” is the number that gets used as the input into the math that does the simulation. By using the same seed as the input, you are guaranteed the same world will be generated when you run Minecraft’s world generation sequence.

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.