Random fun (xoroshiro)

Le hasard souvent fait plus que la science. - Proverbe Français

caption

SplitMix64

uint64_t x{}; /* The state can be seeded with any value. */

uint64_t next()
{
    uint64_t z = (x += UINT64_C(0x9E3779B97F4A7C15));
    z = (z ^ (z >> 30)) * UINT64_C(0xBF58476D1CE4E5B9);
    z = (z ^ (z >> 27)) * UINT64_C(0x94D049BB133111EB);
    return z ^ (z >> 31);
}

xoroshiro128+ (XOR/shift/rotate) / wikipedia

The lowest bits of the output generated by xoroshiro128+ have low quality. The authors of xoroshiro128+ acknowledge that it does not pass all statistical tests, stating: We suggest to use its upper bits for floating-point generation.

Xorshift128+ fails BigCrush when selecting the least significant 32 bits and reversing the bit order… The recommended replacement for xorshift128+, xoroshiro128+, also fails BigCrush in a similar manner… Xoroshiro is no faster than … splitmix64, and SplittableRandom passes BigCrush - The Xorshift128+ random number generator fails BigCrush

#include <random>

random_device rd;
/* The state must be seeded so that it is not everywhere zero. */
uint64_t s[2] = { (uint64_t(rd()) << 32) ^ (rd()),
    (uint64_t(rd()) << 32) ^ (rd()) };

uint64_t xoroshiro128plus(void) {
    uint64_t x = s[0];
    uint64_t const y = s[1];
    s[0] = y;
    x ^= x << 23; // a
    s[1] = x ^ y ^ (x >> 17) ^ (y >> 26); // b, c
    return s[1] + y;
}

see also:

Written on December 22, 2017, Last update on October 17, 2022
random c++ math quote