The OpenD Programming Language

Splittable64

Canonical splittable (specifiable-increment) SplitMix64 engine.

128 bits of state, period of 2 ^^ 64.

import mir.random.engine.splitmix;
@nogc nothrow @safe
alias Splittable64 = SplitMixEngine!(staffordMix13, true)

Examples

import mir.random;
static assert(isSaturatedRandomEngine!Splittable64);
auto rng = Splittable64(1u);
ulong x = rng.rand!ulong;
assert(x == 10451216379200822465UL);

//Split example:
auto rng1 = Splittable64(1u);
auto rng2 = rng1.split();

assert(rng1.rand!ulong == 17911839290282890590UL);
assert(rng2.rand!ulong == 14201552918486545593UL);
assert(rng1.increment != rng2.increment);
import mir.random;
import std.range.primitives: isRandomAccessRange;
// Splittable64 should be both a Mir-style saturated
// random engine and a Phobos-style uniform RNG
// and random access range.
static assert(isPhobosUniformRNG!Splittable64);
static assert(isRandomAccessRange!Splittable64);
static assert(isSaturatedRandomEngine!Splittable64);

Splittable64 a = Splittable64(1);
immutable ulong x = a.front;
Splittable64 b = a.save;
assert (x == a.front);
assert (x == b.front);
assert (x == a[0]);

immutable ulong y = a[1];
assert(x == a());
assert(x == b());
assert(a.front == y);

Meta