Last active
August 29, 2015 14:04
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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