I recently discovered that V8, the engine behind Node.js and Chrome, has been using xorshift128+ since 2014. Out of curiosity, I checked what the Lua VM uses, and to my surprise, it relies on the standard C library, which is extremely slow.
I’m currently working on a game that uses random in the main loop, which is quite slow. So to work around that, I implemented a pseudo-random function.
This is a Linear Congruential Generator (LCG) — one of the oldest and simplest methods for generating pseudorandom numbers. For the noise effect, I end up calling random up to 6 times per loop, which is extremely costly, and not even the C++ implementation of xorshift128+ below could save me.
Anyway, I ended up replacing Lua’s implementation with the one below, because optimizations are always welcome — especially when the gain in randomness is significantly higher.