Last active
November 12, 2023 00:08
-
-
Save keijiro/24f9d505fac238c9a2982c0d6911d8e3 to your computer and use it in GitHub Desktop.
Pseudo random number generator in HLSL using a hash function from H. Schechter & R. Bridson
This file contains 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
// Hash function from H. Schechter & R. Bridson, goo.gl/RXiKaH | |
uint Hash(uint s) | |
{ | |
s ^= 2747636419u; | |
s *= 2654435769u; | |
s ^= s >> 16; | |
s *= 2654435769u; | |
s ^= s >> 16; | |
s *= 2654435769u; | |
return s; | |
} | |
float Random(uint seed) | |
{ | |
return float(Hash(seed)) / 4294967295.0; // 2^32-1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment