Chaos Project

Game Development => Sea of Code => Topic started by: SBR* on November 21, 2011, 03:52:20 pm

Title: Java Random number generator w/seeds
Post by: SBR* on November 21, 2011, 03:52:20 pm
I've been looking into MC's world spawning mechanics - slime chunks to be more specific - and I discovered that it works with a random number generator with seeds. Is there an algorithm to this generator? I would really like to be able to find slimechunks using a calculator instead of a program :). I've tried to Google it, but once again, he isn't my friend.

The slime chunk algorithm is:
Random rnd = new Random(seed + (long) (xPosition * xPosition * 0x4c1906) + (long) (xPosition * 0x5ac0db) + (long) (zPosition * zPosition) * 0x4307a7L + (long) (zPosition * 0x5f24f) ^ 0x3ad8025f);
return rnd.nextInt(10) == 0


P.S. I do have some basic knowledge of languages like Java and C (I can understand the algorithm above), but I'm no expert in it whatsoever, especially not in Java.
Title: Re: Java Random number generator w/seeds
Post by: Ryex on November 21, 2011, 04:05:22 pm
true random numbers arn't really possible most random generators use seeds and if you have the same seed you will get the same numbers in the same order. most languages use the current time since EPOCH as a initial seed. it is impossible to predict random numbers without knowing the initial seed. if you do know it how ever it is as easy as using the same rand function with the seed to find the numbers it threw out.
Title: Re: Java Random number generator w/seeds
Post by: stripe103 on November 21, 2011, 04:36:26 pm
Or you could do what a modder did with a minimap(Rei, I think he was called) and read the save files and check each chunk if it is a slime chunk or not. I think he did it that way at least .
Title: Re: Java Random number generator w/seeds
Post by: SBR* on November 22, 2011, 04:42:10 pm
Ok, thanks all :).
Title: Re: Java Random number generator w/seeds
Post by: Zeriab on November 26, 2011, 11:46:50 am
Yes you can use a calculator to figure it out as long as you know what the seed variable is. I wouldn't suggest doing that.
Instead I would suggest simply simulating the behavior.
I.e. iterating over the xPosition and zPosition variables and then testing whether the code you posted returns true or false. You can do this because rnd.nextInt(10) always returns the same number with the same seed.
You can also do as stripe suggests in which cause you don't have to know the seed.

*hugs*

@Ryex: Getting true random numbers is possible and true random number generators do exist, but they are fairly slow in producing numbers as they rely on chaotic physical phenomenons.
Title: Re: Java Random number generator w/seeds
Post by: SBR* on November 26, 2011, 05:16:14 pm
Hmm... That's sad. But whatever, what can you do about it :).

EDIT: Thank you all, btw :).