The OpenD Programming Language

Xoroshiro128Plus

xoroshiro128+ (XOR/rotate/shift/rotate) generator. 64 bit output. 128 bits of state. Period of (2 ^^ 128) - 1.

Created in 2016 by David Blackman and Sebastiano Vigna as the successor to Vigna's extremely popular xorshift128+ generator used in the JavaScript engines of Google Chrome, Mozilla Firefox, Safari, and Microsoft Edge. From the authors:

<blockquote> This is the successor to xorshift128+. It is the fastest full-period generator passing BigCrush without systematic failures, but due to the relatively short period it is acceptable only for applications with a mild amount of parallelism; otherwise, use a xorshift1024* generator.

Beside passing BigCrush, this generator passes the PractRand test suite up to (and included) 16TB, with the exception of binary rank tests, as the lowest bit of this generator is an LFSR. The next bit is not an LFSR, but in the long run it will fail binary rank tests, too. The other bits have no LFSR artifacts.

We suggest to use a sign test to extract a random Boolean value, and right shifts to extract subsets of bits. </blockquote>

Public domain reference implementation: .

Constructors

this
this(ulong x0)

Constructs an Xoroshiro128Plus generator seeded with x0.

Postblit

A postblit is present on this object, but not explicitly documented in the source.

Members

Functions

jump
void jump()

This is the jump function for the generator. It is equivalent to 2^^64 calls to opCall(); it can be used to generate 2^^64 non-overlapping subsequences for parallel computations.

opCall
ulong opCall()

Advances the random sequence.

popFront
void popFront()
seed
void seed(ulong x0)

Compatibility with Phobos library methods. Presents this RNG as an InputRange.

Manifest constants

isRandomEngine
enum isRandomEngine;

Properties

front
ulong front [@property getter]
save
typeof(this) save [@property getter]
empty
enum bool empty;

Compatibility with Phobos library methods. Presents this RNG as an InputRange.

Variables

isUniformRandom
enum bool isUniformRandom;

Compatibility with Phobos library methods. Presents this RNG as an InputRange.

max
enum ulong max;

Largest generated value.

min
enum typeof(this.max) min;

Compatibility with Phobos library methods. Presents this RNG as an InputRange.

preferHighBits
enum bool preferHighBits;

The lowest bit of this generator is an LFSR. The next bit is not an LFSR, but in the long run it will fail binary rank tests, too. The other bits have no LFSR artifacts. To provide some context, every bit of a Mersenne Twister generator (either the 32-bit or 64-bit variant) is an LFSR.

s
ulong[2] s;

State must not be entirely zero. The constructor ensures this condition is met.

Examples

import mir.random.engine : isSaturatedRandomEngine;
static assert(isSaturatedRandomEngine!Xoroshiro128Plus);
auto gen = Xoroshiro128Plus(1234u);//Seed with constant.
assert(gen() == 5968561782418604543);//Generate number.
foreach (i; 0 .. 8)
    gen();
assert(gen() == 8335647863237943914uL);
//Xoroshiro128Plus has a jump function that is equivalent
//to 2 ^^ 64 invocations of opCall.
gen.jump();
auto n = gen();

Meta