>>5695923Wow, I did not know this Wuxian! I had a look at pseudorandom generators when I was writing some dice / random table generators myself. Mostly I think people use the Mersenne twister,
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::mt19937 mt_generator(seed);
int random(int rmin, int rmax){
std::uniform_int_distribution < int >distribution(rmin, rmax);
return distribution(mt_generator);
}
All of these are just more complex variants of take extremely large number, perform operation and then truncate or modulo eg take some huge number like 5358979323846 square it then your middle digit is the pseudorandom number etc. then repeat process get middle digit for next random number etc.
I think one popular pseudorandom trick I have seen used in shaders is the sine spike trick, like this:
float random (in vec2 st) {
return fract(sin(dot(st.xy,
vec2(12.9898,78.233)))
* 43758.5453123);
}
I have only ever encountered issues with pseudorandom numbers running some shaders from Shadertoy, because what happens is some of the shaders are animated over time. So billions of pixel operations executed again and again say at 60fps per second over time, eventually exposes the deterministic nature of the pseudorandom generation, it typically starts looking like streaked or repetitive sine wave like patterns in what should be solid blocks of colour or say perlin or simplex noise etc. But in general most of the pseudorandom numbers are good enough for me!