It just does a bunch of random bitwise operations on the numbers 4 seeds, mutating them each time. This code is designed to mimic randomness, it doesn’t need to be perfect, just fast. There really isn’t much point in trying to understand it, unless you specifically want to know how to write random functions, or.perhaps hashing functions. Why did you choose this function?
The range is the entire range of the uint32 - so 2.pow(32).
Do the number have any special meaning? No, the entire function is chosen because it gives a good enough approximation of randomness and is fast. That being said, you would interpret the numbers, not as values, but as binary bits. There are some tactics employed in these types of function to help generate randomness, but they are not a property of randomness, but of the binary representation, also, bitshift operations are used because computers can calculate these cheaply, in shader code you will normally see the dot product used as that cheap to compute on a gpu.
This isn’t equal to minus 2, as its an unsigned int, but 2.pow(32) - 3
If you understand what all the operators do, then you already understand what the algorithm does, its just a cheap to compute complex mess that makes something that looks random. This sort of makes sense, it is a random function after all!
Honestly, I think spending too much time on this is a waste, there are people out there who have spent years bench-marking many different combinations trying to find the fastest whilst also sufficiently uniform function. There are many other aspects of DSP code that would be worth spending time to study instead.
Thank you, thank you so much.
Your kind explanations and recommendations are very helpful.
Using shader examples to understand about random function would be worth.
I am looking around some SuperCollider source code recently, mostly it looks complicate but fun to understand even it is a tiny thing.
I’d be a little weary of this if you aren’t super familiar with c++. The issue is that supercollider was started in the later 90s, early 2000s and c++ basically became a different language in 2011. Reading and learning C++ is a lot like archeology.
As a result there are a lot of bad practices in the code. There has been an effort change this, but refactoring legacy code is hard! If I where you, I’d close by eyes every time you see something in all caps (it’s a macro, particularly the silly LOOP thing), and raw pointers (the us government actually recommends against using c++ because of issue with raw pointers - to simplify somewhat…).
Whilst reading the code base is really good and you should definitely do it(!), don’t use it as an example of how to write good, safe, fast C++ code in 2022.