Skip to content

Instantly share code, notes, and snippets.

@keijiro
Last active April 22, 2024 16:32
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save keijiro/ee7bc388272548396870 to your computer and use it in GitHub Desktop.
Save keijiro/ee7bc388272548396870 to your computer and use it in GitHub Desktop.
One liner pseudo random generator with HLSL
float nrand(float2 uv)
{
return frac(sin(dot(uv, float2(12.9898, 78.233))) * 43758.5453);
}
@SpicyMelonYT
Copy link

Thanks for the code! It was very simple but it was exactly what I was looking for with a quick google search.

@mikec316
Copy link

ChatGPT found and used this exact snippet whilst I was asking it to convert some code to HLSL and needed a random generator.

@SpicyMelonYT
Copy link

SpicyMelonYT commented Apr 21, 2024

@mikec316 well for how simple this code is (now that I have the years of experience) I am surprised GPT did not just write it out instead of finding a link? Did you ask for it to find it online specifically?

@mikec316
Copy link

@mikec316 well for how simple this code is (now that I have the years of experience) I am surprised GPT did not just write it out instead of finding a link? Did you ask for it to find it online specifically?

ChatGPT wrote it out exactly as it appears above, no link. I just managed to find the link while verifying :D

@SpicyMelonYT
Copy link

@mikec316 ah ok yeah that is because its a well known function from long before @keijiro wrote it. Its a simple concept really, but for a more effective aproach make sure that if you are using the noise within a texture or some finite space that you divide the uv by a float2(width, height). Or multiply it, i forget. Its to make SURE there is no repeating pattern

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment