Finding a specific index of the Random class

Hi, i’m delving into procedural generation and want to generate random numbers based off coordenates, i was hoping to be able to set up a seed, and then full each of these coordenates up with random values that i can reference later on without having to generate all of my other coordinates as well.

Say i have a 1000x1000 grid matrix, its easy enough to make the Random spit out 0,0 which would be the first value, but if i want to get the value at 1000,1000 do i really have to cycle through all 1000000 coordinates first to get the same value if its not held in memory already?

I’m looking for some way to reference Random like i would an array, to get that 1000000th value.
Something like
int coordx = 1000;
int coordy = 1000;
int seed = 1234;
Random.Initstate(seed);
Random.range(0,1)[coordy*1000+coordx]

The only other way i can think of doing it is having the coordenate be the seed, but then there would be a large slowdown if i do iterate over these coordenates right? Since i would need to call Random.Initstate() 1000000 times in a row.

Sounds like you need a Noise function; Unity has built-in Perlin Noise:

You set up the noise with a single seed, and then you can just access it by coordinates as you’re doing above, and always get the same value at any coordinate for the same seed regardless of what order you access them in.

Hmm, for what I’m doing, i think ill need a noise that outputs double values. Luckily i have a library that does just that that i didn’t think to use for this. Thank you for the suggestion, it helped a lot.

What you want is a random hash, if you a have fixed sized world, I would recommend a random perfect hash.

more + algorithm there:

Noise does one more thing besides being indexable. It also gives continuous values. noise(40) won’t be too far away from noise(39). In other words, it pretends someone is drawing a wavy (maybe very wavy) line, rather than just rolling dice.

Contiguous noise, like Prelin noise, has this characteristic.

But if this isn’t desired there are non contiguous noise implementations.