The OpenD Programming Language

PhobosRandom

Extends a Mir-style random number generator to also be a Phobos-style uniform RNG. If Engine is already a Phobos-style uniform RNG, PhobosRandom is just an alias for Engine.

  1. struct PhobosRandom(Engine)
  2. template PhobosRandom(Engine)
    template PhobosRandom (
    Engine
    ) if (
    isRandomEngine!Engine &&
    isPhobosUniformRNG!Engine
    ) {}

Examples

import mir.random.engine.xorshift: Xorshift1024StarPhi;
import std.random: isSeedable, isPhobosUniformRNG = isUniformRNG;
import std.range.primitives: isForwardRange;

alias RNG = PhobosRandom!Xorshift1024StarPhi;

//Phobos interface
static assert(isPhobosUniformRNG!(RNG, ulong));
static assert(isSeedable!(RNG, ulong));
static assert(isForwardRange!RNG);
//Mir interface
static assert(isSaturatedRandomEngine!RNG);
static assert(is(EngineReturnType!RNG == ulong));

auto gen = Xorshift1024StarPhi(1);
auto rng = RNG(1);
assert(gen() == rng.front);
rng.popFront();
assert(gen() == rng.front);
rng.popFront();
assert(gen() == rng());

gen.__ctor(1);
rng.seed(1);
assert(gen() == rng());

Meta