sjs icon indicating copy to clipboard operation
sjs copied to clipboard

Consider switching to xoroshiro128+ for RNG

Open fatcerberus opened this issue 9 years ago • 1 comments

I recently switched from Mersenne Twister (MT19937) to xoroshiro128+ for random number generation in minisphere. It's about 4 times as fast as MT, generates 64-bit unsigned integers, is higher quality (i.e. passes more randomness tests), and is in the public domain. It's the successor to the xorshift128+ algorithm currently used by SpiderMonkey and V8:

  • xoroshiro128+ http://xoroshiro.di.unimi.it/

The implementation I wrote for minisphere allows creating multiple generator instances as well as saving and restoring the state of the generator. Since the state is only 128-bit it can be represented as a single 32-character hex string that you can write to a file and read back later. MT19937 has nearly 2.5KB of state making it a bit unwieldy.

Here's my implementation if you want to look at it:

  • https://github.com/fatcerberus/minisphere/blob/master/src/shared/xoroshiro.c

fatcerberus avatar Jun 02 '16 07:06 fatcerberus

Thanks for the heads up!

saghul avatar Jun 02 '16 21:06 saghul