Trying to convert some code, but for all my googling I can’t figure out how to convert this bit.
float fR = fHatRandom(fRadius);
float fQ = fLineRandom(fAngularSpread ) * (rand()&1 ? 1.0 : -1.0);
float fK = 1;
This bit
(rand()&1 ? 1.0 : -1.0);
I can’t figure out.
The C++ sample generates a random number, uses its lowest bit and throws away the rest. The lowest bit is then used to pick either -1 or 1.
In C#, the equivalent is as follows.
Important: If you do this in a loop, store the instance of
Randomsomewhere and only callNextin the loop, not the constructor again. This is not only a performance optimization. You would otherwise see sequences of identical bits of duration of approximately 100 ms, so calls to the parameterless constructor of Random should be few and far between, ideally one per your app’s startup.