SplitMix64

This is a fixed-increment version of Java 8's SplittableRandom generator. It is a very fast generator passing BigCrush, and can be useful if for some reason exactly 64 bits of state are needed; otherwise, it is suggested to use Xoroshiro128plus (for moderately parallel computations) or Xorshift1024star (for massively parallel computations).

The generator period is 2 ^^ 64.

Disabled Default Constructor

A disabled default is present on this object. To use it, use one of the other constructors or a factory function.

Constructors

this
this(ulong s)

Constructor (RNG instances can only be initialized with a specified seed).

Postblit

Copying this object is disabled.

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

Members

Functions

dup
typeof(this) dup()

Provides a copy of this RNG instance with identical internal state.

front
ulong front()
popFront
void popFront()

Range primitives

seed
void seed(ulong s)

(Re)seeds the generator.

Variables

empty
enum bool empty;

Range primitives

isUniformRandom
enum bool isUniformRandom;

Marks this range as a uniform random number generator

max
enum ulong max;

Largest generated value

min
enum ulong min;

Smallest generated value (0)

Examples

1 import std.array : array;
2 import std.random : isUniformRNG, randomSample, uniform;
3 import std.range : iota, take;
4 import dxorshift.splitmix64;
5 
6 // splitmix64 generators must be initialized
7 // with a specified seed
8 auto gen = SplitMix64(123456);
9 
10 // verify it is indeed a uniform RNG as defined
11 // in the standard library, whether accessed
12 // directly or via a pointer
13 static assert(isUniformRNG!(typeof(gen)));
14 static assert(isUniformRNG!(typeof(&gen)));
15 
16 // since the postblit is disabled, we must
17 // pass a pointer to any functionality that
18 // would otherwise copy the RNG by value
19 assert((&gen).take(2).array == [4172122716518060777uL,
20                                 4753009419905186825uL]);
21 
22 // this means, of course, that we must guarantee
23 // the lifetime of the pointer is valid for the
24 // lifetime of any functionality that uses it
25 auto sample = iota(100).randomSample(10, &gen).array;
26 
27 // however, we can pass the RNG as-is to any
28 // functionality that takes it by ref and does
29 // not try to copy it by value
30 auto val = uniform!"()"(-0.5, 0.5, gen);
31 
32 // in circumstances where we really want to
33 // copy the RNG state, we can use `dup`
34 auto gen2 = gen.dup;
35 assert((&gen).take(3).array == (&gen2).take(3).array);

Meta

Credits

This implementation is ported from the public-domain C implementation by Sebastiano Vigna, available at http://xoroshiro.di.unimi.it/splitmix64.c

For more details on the SplittableRandom generator, see http://dx.doi.org/10.1145/2714064.2660195 and http://docs.oracle.com/javase/8/docs/api/java/util/SplittableRandom.html