Skip to content

Instantly share code, notes, and snippets.

@tinylucid
Created June 16, 2023 12:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tinylucid/6f42c4e6aba7a75c6b9dbd59a16fdbe2 to your computer and use it in GitHub Desktop.
Save tinylucid/6f42c4e6aba7a75c6b9dbd59a16fdbe2 to your computer and use it in GitHub Desktop.
PCG_RNG hash function
// https://www.reedbeta.com/blog/hash-functions-for-gpu-rendering/
uint pcg_hash(uint input)
{
uint state = input * 747796405u + 2891336453u;
uint word = ((state >> ((state >> 28u) + 4u)) ^ state) * 277803737u;
return (word >> 22u) ^ word;
}
{
uint rng_state;
uint rand_pcg()
{
uint state = rng_state;
rng_state = rng_state * 747796405u + 2891336453u;
uint word = ((state >> ((state >> 28u) + 4u)) ^ state) * 277803737u;
return (word >> 22u) ^ word;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment