Skip to content

Instantly share code, notes, and snippets.

@keijiro
Last active November 12, 2023 00:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keijiro/24f9d505fac238c9a2982c0d6911d8e3 to your computer and use it in GitHub Desktop.
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
// 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