randomseedprng

How to generate a seed from an xy coordinate


Iv'e been working on a perlin script but have been having problems with creating simple pseudo random values.

I need to be able to create a seed value from an xy coordinate but x+y has obvious problems with recurring values. Also they go into negative space so x^y doesn't work.

Sorry if this has been already answered somewhere else but either I didn't understand or couldn't find it.


Solution

  • You need to better define the problem to get an optimal answer.

    If your x and y values are relatively small, you could place them into the high and low portions of an integer (is the seed in your language an integer), e.g. for a 32-bit platform:

    int seed = x << 16 + y;

    If the seed value is not allowed to be negative (I didn't fully understand what you meant by "negative space" in your question, whether you were referring to geography or the seed value), you can take the absolute value of the seed.

    If you meant that the coordinates can have negative values, your best course of action depends on whether you want the same seed for a coordinate and for it's inverse.