Hi!
I need a random noise function for my game (returns from 0 to 1 depending on given x and y coordinate, but keeps repeating the same value for a set of coords (e.g x=1 y=8, value will always be for example 0.45)). I have an array with number from 0 to 255 in random order and following function:
public static float RandomNoise(int xin, int yin) {
return (float)p[((int)((51 + xin) * 51 + yin)) 255] / 255;
}
Unfortunatelly sth. is wrong because it returns a striped pattern!
Please tell me what I am doing wrong!
Have you done a debug.log of what the resulting value of (int)((51 + xin) * 51 + yin) 255 ends up being every time so you can examine the logic’s effectiveness?
Alright, I solved the problem: hash - Hashing 2D, 3D and nD vectors - Stack Overflow
The general idea is as follows: ((x * prime) XOR (y * prime)) % hashTableLength.
The prime numbers don’t have to be so big. I’ve used 811 and 547 and it works fine.
Writing it just in case someone has run into similar problem. Thanks for all the replies.