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)

Constructors

this
this(UIntType x0)

Constructs a XorshiftEngine generator seeded with x0.

Members

Functions

popFront
void popFront()

Advances the random sequence.

seed
void seed(UIntType x0)

(Re)seeds the generator.

Manifest constants

empty
enum empty;

Always false (random generators are infinite ranges).

Properties

front
UIntType front [@property getter]

Returns the current number in the random sequence.

save
typeof(this) save [@property getter]

Captures a range state.

Variables

isUniformRandom
enum bool isUniformRandom;

Mark this as a Rng

max
enum UIntType max;

Largest generated value.

min
enum UIntType min;

Smallest generated value.

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

Suggestion Box / Bug Report