Search code examples
javarandomnoisepoissonprocedural-generation

Is there an algorithm or function that outputs a random number given n number values?


So I have been working on a game that utilizes procedural terrain & structure generation. Right now, I am tackling structure generation - which I used Poisson-Disc sampling, which I plan to implement on chunks in my world. However, my sampling relies on one single seed. Is there a way to accept 3 or more numbers to output a random number somehow related to those numbers?

On another note, the random number doesn't have to be within the possible ranges of the inputs.

If it is not possible, are there any other paradigms to implement Poisson Disc sampling (or alternatives thereof) on an infinite procedurally-generated world to create structures? I am kinda stuck.

Example:

Random x = new Random(138013, 28282, 37920)
x.nextInt() = 38309
Random y = new Random(138012, 28282, 37920)
y.nextInt() = 28323
Random z = new Random(138013, 28282, 37920)
z.nextInt() = 38309
//new Random(a,b,c).nextInt() does not have to be within ranges [a,b], [a,c], [b,c]

Solution

  • You could create the seed by joining these three values:

    new Random(138013, 28282, 37920) => new Random("138013" + "28282" + "37920")
    

    It's not valid code, but I hope you get the principle. The string should be then converted to long. If the number is too large for long, maybe you could apply a ceratain modulo. Like 138013 % 10000 and do that for every value. Or you could sum these three values.