The OpenD Programming Language

XorshiftEngine

Xorshift generator. Implemented according to Xorshift RNGs (Marsaglia, 2003) with Sebastino Vigna's optimization for large arrays.

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

struct XorshiftEngine (
UIntType
uint bits
int sa
int sb
int sc
) if (
isUnsigned!UIntType
) {}

Constructors

this
this(UIntType x0)
this(uint x0)

Constructs a XorshiftEngine generator seeded with x0.

Postblit

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

Members

Functions

opCall
UIntType opCall()

Advances the random sequence.

Manifest constants

isRandomEngine
enum isRandomEngine;

Marker for mir.random.isRandomEngine

Variables

max
enum UIntType max;

Largest generated value.

Parameters

UIntType

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

bits

The number of bits of state of this generator. This must be a positive multiple of the size in bits of UIntType. If bits 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.

Note: For historical compatibility when bits == 192 and UIntType is uint a legacy hybrid PRNG is used consisting of a 160-bit xorshift combined with a 32-bit counter. This combined generator has period equal to the least common multiple of 2 ^^ 160 - 1 and 2 ^^ 32.

Meta