# How do level seeds work?

I see minecraft seeds listed, and I started trying some of my own.

I have noticed using the same seed produces very similar styles of maps, i.e. start in a specific biome, very high mountains etc, but do they reproduce the maps exactly and you just spawn in the same place, or are they just a very specific set of rules for the area you first spawn?

If I have two maps of the same seed, and I walk 1000 blocks north, will the maps be identical/similar or totally random after the first spawn area?

-

Computers are deterministic machines, incapable as such of non-deterministic (= random) behavior. What they can do is use complex math to simulate random behavior: this gives pseudo-random numbers.

For example, when I run Python 3 for Windows 7 I get:

>>> import random
>>> random.seed(1) #I set the seed to a fixed value...
>>> random.random() #and ask for 3 "random" numbers
0.13436424411240122
>>> random.random()
0.8474337369372327
>>> random.random()
0.763774618976614


I then connect to an Ubuntu 11.04 machine with Python 2, and get:

>>> import random
>>> random.seed(1) #I set again the seed to the previous fixed value
>>> random.random() #and ask again for 3 "random" numbers
0.13436424411240122
>>> random.random() #...doesn't look very random, does it?
0.8474337369372327
>>> random.random()
0.763774618976614


So, the same pseudo-random engine will always give the same numbers in the same order. This doesn't imply the game actually uses the same numbers in the same way, however, as yx_ insightfully thought. However, the game could be written in a way to ensure this; for example, one could derive from each seed (say, "foo") a different seed per each block (say, "foo@1@2" to determine the chunk 1,2). How can we tell how this is done?

There's only one way to know!

I used the seed "Mersenne" to create two worlds, a world A and a world B.

In world A I spawned in world A at (262.5, -280.5); I attempted to move in the direction I spawned in as straight as possible for 500 units, then back for a thousand. This is what I got.

In world B I spawned in (+259.5, -276,5), just to make things easier. I attempted to move in the direction opposite to the one I spawned in for 500 units, then back for a thousand; in short, I travelled back and forth on the same 1.5 km, just in a different order. This is what I got.

(Keep in mind that, as I explored, I removed blocks here and there for navigational purposes.)

This results are shockingly identical. I say shockingly because I certainly had the impression the two worlds were quite similar... but not quite the same.

Indeed, if we zoom on the spawn point, we can see some differences... but it is mainly only about trees. The underground area is not pictured, and identical.

In short: the seed system is almost perfect and the same seed will give you two worlds that are almost identical to each other. I haven't tried the nether, but I have no reason to believe it would behave differently.

-
+1 for an excellent investigation – fredley May 18 '11 at 14:24
The only way the trees can be placed differently is if the software uses another, independent seed (the time from the system clock is a very common one) to decide on tree placement which would explain the minor differences. – rmx May 18 '11 at 14:51
The strangest thing by far is how most of the trees seem to be identical! – fredley May 18 '11 at 15:51
@rmx: The other possibility is that the program isn't deterministic - in particular, if multiple threads read off of the same random number generator, variation from run to run could essentially swap random numbers around from one place to another. – Jefromi May 18 '11 at 16:16
@Jefromi Minecraft is (currently) single-threaded. – SevenSidedDie May 19 '11 at 1:31

The seed in Minecraft is used as a random seed, i.e. it causes the terrain generator to produce random terrain, but in a repeatable way. Using the same seed will result in identical terrain, for as far as you walk, right down to the flowers, and the nether.

Your spawn point may not be identical, however.

There are around 18 quintillion (18,000,000,000,000,000,000) different possible seeds.

-
I think badp's post proves it's not quite down to the flowers, interestingly enough. – Shinrai May 18 '11 at 14:29
@Shinrai Yes, agreed. Clearly trees are added according to some random generation that's separate to the seed, I wonder if flowers are the same? – fredley May 18 '11 at 15:36
I had the same thought, and my hunch would be 'probably'. Worth investigating, probably... – Shinrai May 18 '11 at 15:44

The seeds for a map in minecraft is used inside a Pseudo Random Generator.

A pseudorandom number generator (PRNG) is an algorithm for generating a sequence of numbers that approximates the properties of random numbers. The sequence is not truly random in that it is completely determined by a relatively small set of initial values, called the PRNG's state.

-
Incorrect, the worlds will be identical. Chunks are not random, and do not 'consume' elements of the hash chain, otherwise the terrain would not be 'continuous'. – fredley May 18 '11 at 13:10
@fredley Not necessarily; the terrain can (and likely, is) smoothed after being randomly generated. – badp May 18 '11 at 13:25
Yeah it looks like the world building is deterministic. twitter.com/jeb_/status/40351239543721984 (is smoothing non-deterministic?) – Matthew Read May 18 '11 at 13:26
@Matthew Read - smoothing would only be stochastic (a much cooler way to say 'random') if it used a random number somewhere in the subroutine. – Raven Dreamer May 19 '11 at 1:01
That was what I meant, yes. – Matthew Read May 19 '11 at 1:40