The OpenD Programming Language

XorshiftEngine

Xorshift generator. Implemented according to Xorshift RNGs (Marsaglia, 2003) when the size is small. For larger sizes the generator uses Sebastino Vigna's optimization of using an index to avoid needing to rotate the internal array.

Period is 2 ^^ nbits - 1 except for a legacy 192-bit uint version (see note below).

  1. struct XorshiftEngine(UIntType, uint nbits, int sa, int sb, int sc)
  2. template XorshiftEngine(UIntType, int bits, int a, int b, int c)
    template XorshiftEngine (
    UIntType
    int bits
    int a
    int b
    int c
    ) if (
    isUnsigned!UIntType &&
    a > 0
    &&
    b > 0
    &&
    c > 0
    ) {}

Parameters

UIntType

Word size of this xorshift generator and the return type of opCall.

Examples

alias Xorshift96  = XorshiftEngine!(uint, 96,  10, 5,  26);
auto rnd = Xorshift96(42);
auto num = rnd.front;  // same for each run
assert(num == 2704588748);

Meta