Java Random number generator w/seeds

Started by SBR*, November 21, 2011, 03:52:20 pm

Previous topic - Next topic

SBR*

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.

Ryex

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.
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

stripe103

November 21, 2011, 04:36:26 pm #2 Last Edit: November 23, 2011, 03:35:21 am by stripe103
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 .

SBR*


Zeriab

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.

SBR*

Hmm... That's sad. But whatever, what can you do about it :).

EDIT: Thank you all, btw :).