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)
    struct 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
    )
    ) {}
  2. template XorshiftStarEngine(StateUInt, uint nbits, int sa, int sb, int sc, StateUInt multiplier, OutputUInt = StateUInt)

Constructors

this
this(StateUInt x0)

Constructs a XorshiftStarEngine generator seeded with x0.

Postblit

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

Members

Functions

jump
void jump()

This is the jump function for the standard 1024-bit generator. It is equivalent to 2 ^^ 512 invocations of opCall(); it can be used to generate 2 ^^ 512 non-overlapping subsequences for parallel computations. This function will only be defined if the shifts are the same as for Xorshift1024StarPhi.

opCall
OutputUInt opCall()

Advances the random sequence.

Manifest constants

isRandomEngine
enum isRandomEngine;

Marker for mir.random.isRandomEngine

Variables

max
enum OutputUInt max;

Largest generated value.

preferHighBits
enum bool preferHighBits;

Note that when StateUInt is the same size as OutputUInt the two lowest bits of this generator are LFSRs, and thus will fail binary rank tests. To provide some context, every bit of a Mersenne Twister generator (either the 32-bit or 64-bit variant) is an LFSR.

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