java - How to get a random number from a 2d coordinate and a seed? -


i'm trying make noise based terrain generation , need random point a coordinate point, , seed. now, hard part i'm struggling having same number returned same point if seed same. (random.nextdouble() makes go other number).

i have tried doing sort of equation:

return ((int) ((randomkey1.charat((5 ^ x) % 127)) + (int) ((randomkey2             .charat(math.abs(z  ^ 2 % 64) % 127)))) / 256f * 40f); 

but doesn't work because if swap x , z coordinates similar number causing terrain mirrored diagonally.

solved:

double getratcor(int x, int z) {     double a;      random r = new random(seed + (x*10000) + (z*100));     = r.nextdouble()*40;     system.out.println(a);     return a; } 

how about?

/** * return random number seed based on coordinates. */ double locationvalue(int x,int y){     long seed = z;     seed = x + (seed << 32); // make x , z semi-independent parts of seed.     random r = new random(seed);     return r.nextdouble(); } 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -