Minecraft Random Seed - How is it generated?

an
- in Worlds
3

If you leave the "Seed" field in Minecraft empty, the seed will be generated randomly, depending on the system time. Means that if two people create a world at the same time, they get the same world.

Now my question: What is meant by "system time", or how exactly does it work?

Seconds? Milliseconds? Or even nanoseconds?

What is being used to produce the seed?

am

I think nanoseconds are used. Google Java Java PRNG.

Sw

Public random () {
this (seedUniquifier () ^ System.nanoTime ());
}

private static long seedUniquifier () {
// L'Ecuyer, "Tables of Linear Congener Generators of
// Different Sizes and Good Lattice Structure ", 1999
for (;;) {
long current = seedUniquifier. Get ();
long next = current * 181783497276652981L;
if (seedUniquifier.compareAndSet (current, next))
return next;
}
}

private static final AtomicLong seedUniquifier
= new AtomicLong (8682522807148012L);

This generates a pseudo-random number when calling Math.random () without a seed. So to your questions: The system time is just the time since any time. https://docs.oracle.com/...l#nanoTime ()

NanoTime () is used here, so it is in nanoseconds.

Now it remains to be seen how Minecraft creates the seed. Probably also by Math.random () or just functioning functions. Possibly but also several numbers generated in this way offset against each other. To find out, you would have to take a look at the source code of Minecraft, but that was too time-consuming for me.

So Math.random () always returns the same value if the system time is the same. But since the system time counts from any point in time, another number is output, even if it is called at exactly the same time (in two different programs).

And since Minecraft probably uses not only a simple Math.random () for the Seed, but probably several, due to different delays of the code (depending on components, open programs etc) Math.random () will change the system time each time even if the generation started with the same system time.

Al

I think it's also related to how long the PC is on