Q:

How to create reproducible probability in map generation?

So for my game, I'm using perlin noise to generate regions of my map (water/land, forest/grass) but I'd also like to create some probability based generation too. For instance:
if(nextInt(10) > 2 && tile.adjacentTo(Type.WATER))
    tile.setType(Type.SAND);

This works fine, and is even reproduceable (based on a common seed) if the nextInt() calls are always in the same order. The issue is that in my game, the world is generated on demand, based on the player's location. This means, that if I explore the map differently, and the chunks of the map are generated in a different order, the randomness is no longer consistent.
How can I get this sort of randomness to be consistent, independent of call order?
Thanks in advance :)

A:

This is simple, create a new Random() object for each chunk, using that chunk's position as the seed. 
If you think of Random as a really (really) long series of numbers, the seed is just where to start iterating through. So, if you always set the seed before generating the chunk, you'll always get the same integers, in the same order.
EDIT

But how do you ensure that each chunk gets a unique seed?

It's not too critical to get a unique seed for each chunk, unless you want to try to guarantee that each chunk is unique from the last. I say try because even if each seed is unique it doesn't necessarily guarantee the random numbers you get will be different. If your world has a maximum size, you can get a unique long from each position in the world with a method like this:
public long positionToLong(int x, int y, int z, int maxY, int maxZ) {
    return (x * (MaxZ * maxY)) + (y * maxZ) + z;
}

If it doesn't have a maximum size, you can use some algorithm like:
public long positionToLong(int x, int y, int z) {
    return x + y + z + (x*x) + (y*y) + (z*z);
}

Then you can do additional things to strive for unique seeds, like add the distance from the center of the world.
I should mention how I do this in my game. Since I'm generating terrain shape along with terrain type, I wanted to ensure that I'd have continuity between chunks. I did that by using a single world seed. Then the Perlin noise function takes the absolute world position as an input. This makes the transition between chunks seemless, which will not be the case if you're randomly generating each chunk distinct from the others.

