The OpenD Programming Language

XorshiftStarEngine

Template for the xorshift* family of generators (Vigna, 2016; draft 2014).

<blockquote> xorshift* generators are very fast, high-quality PRNGs (pseudorandom number generators) obtained by scrambling the output of a Marsaglia xorshift generator with a 64-bit invertible multiplier (as suggested by Marsaglia in his paper). They are an excellent choice for all non-cryptographic applications, as they are incredibly fast, have long periods and their output passes strong statistical test suites. </blockquote>

  1. struct XorshiftStarEngine(StateUInt, uint nbits, int sa, int sb, int sc, StateUInt multiplier, OutputUInt = StateUInt)
  2. template XorshiftStarEngine(StateUInt, uint nbits, int sa, int sb, int sc, StateUInt multiplier, OutputUInt = StateUInt)
    template XorshiftStarEngine (
    StateUInt
    uint nbits
    int sa
    int sb
    int sc
    StateUInt multiplier
    OutputUInt = StateUInt
    ) if (
    isUnsigned!StateUInt &&
    isUnsigned!OutputUInt
    &&
    OutputUInt.sizeof <= StateUInt.sizeof
    &&
    (
    sa > 0 &&
    sb > 0
    &&
    sc > 0
    )
    ) {}

Parameters

StateUInt

Word size of this xorshift generator.

nbits

The number of bits of state of this generator. This must be a positive multiple of the size in bits of UIntType. If nbits is large this struct may occupy slightly more memory than this so it can use a circular counter instead of shifting the entire array.

sa

The direction and magnitude of the 1st shift. Positive means left, negative means right.

sb

The direction and magnitude of the 2nd shift. Positive means left, negative means right.

sc

The direction and magnitude of the 3rd shift. Positive means left, negative means right.

multiplier

Output of the internal xorshift engine is multiplied by a constant to eliminate linear artifacts except in the low-order bits. This constant must be an odd number other than 1.

OutputUInt

Return type of opCall. By default same as StateUInt but can be set to a narrower unsigned type in which case the high bits of the multiplication result are returned.

Note: If sa, sb, and sc are all positive (which if interpreted as same-direction shifts could not result in a full-period xorshift generator) the shift directions are instead implicitly right-left-right when bits == UIntType.sizeof * 8 and in all other cases left-right-right. This maintains full compatibility with older versions of XorshiftStarEngine that took all shifts as unsigned magnitudes.

Meta