Random noise is striped!

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! :face_with_spiral_eyes:

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?

Are you expecting that final division by 255 to be processed as integer or floating point division? Either way, I would check the assumption.

why not use mathf.perlin? there are also some free noise solutions available (some libnoise port fe).

Can I assume that mathf.perlin return a random noise value (not smoothed or processed in any way) when used like: Math.PerlinNoise(x51, y51)?

Use smaller values

No, it’s perlin noise, not random.

–Eric

So how to make a totally random hash function but returning the same values for the same parameters?

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.

Best Regards
Jarek