Skip to content

Instantly share code, notes, and snippets.

@Ratstail91
Last active August 29, 2015 14:04
Show Gist options
  • Save Ratstail91/bd6a35ec598b4f2090ba to your computer and use it in GitHub Desktop.
Save Ratstail91/bd6a35ec598b4f2090ba to your computer and use it in GitHub Desktop.
A simple hashing function, to emulate a procedural number generator for perlin noise.
unsigned hashuint(unsigned x) {
//found this on stack overflow
x = ((x >> 16) ^ x) * 0x45d9f3b;
x = ((x >> 16) ^ x) * 0x45d9f3b;
x = ((x >> 16) ^ x);
return x;
}
unsigned hashCoordinates(unsigned seed, int x, int y) {
//default values when 0 is a parameter
if (!seed) seed = 211268;
if (!x) x = 21795;
if (!y) y = 8081991;
//these arguments result in interference
seed = hashuint( (x + 1096 + y / 2) ^ (y + 20000 + x / 3) ^ seed);
x = hashuint(x + 1096 + y / 2);
y = hashuint(y + 20000 + x / 3);
//return a single value by XOR
return seed ^ x ^ y;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment