Note: There are probably ways to get even greater performance (I’m thinking, generating a random wavetable every block, - but I know that that’s hotly debated, and beyond the scope of this particular project, although a fine second project! If you have any suggestions/ideas for me to investigate).
Ahh thank you. I tested both Xorshift and SC’s Taus both with the cunning trick and with the * 2 - 1 method, and it appears (at least for me/today) that the * 2 - 1 method just eked out a slight advantage.
I have added the taus algorithm to my githup repo. And yes, although they are ‘better’ until I run into any problems, I guess I’m going to stick to my trusty but shitty xorshift
If you only need white noise (not an RNG), the xorshift (and other LFSR based approaches) can be modified to generate one random bit which means you don’t need to scale, just cast. It’s counterintuitive but to my ears, noise that is just 0s or 1s sounds quite smooth (un-normalized of course).
I’ve used the example on that wikipedia article, just take the LSB of the feedback shift register
float sample = lfsr & 0x1 ? 1.0f : -1.0f;
I’m no expert on RNGs but my understanding is that the LFSR technique (which on first impressions is what xorshift uses) generates a random bit with 50% probability of being 1 or 0 in the LSB. So if you map that to +1 or -1 then you get what amounts to clipped white noise.
Disclaimer: I heard about this from a colleague a few years ago
yup, I haven’t dug in too deeply. iirc the importance of the algorithm is how many samples it takes to repeat the sequence, which for noise generation isn’t such a big deal. But mapping the algorithm to an int in a certain range and then casting to a float in the [-1,1] range looks to be a bit more expensive than just taking the lowest bit. You may want to do some benchmarks to be sure, processors are weird.
So in terms for using it for noise, it does seem to make a slightly grittier (especially after transformations) noise, to my ears the frequency response is a little different as well, I think - more mid range - which may or not suit your taste. But for “most” applications, I’m gonna say better to return float * 2 - 1
However for generating a random bool or random sign - it’s a winner! So thank you. Have added it to my aresenal!