View source code
Display the source code in std/random.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

Struct std.random.XorshiftEngine

Xorshift generator using 32bit algorithm.

struct XorshiftEngine(UIntType, UIntType bits, UIntType a, UIntType b, UIntType c)
  
if (isUnsigned!UIntType);

Implemented according to Xorshift RNGs. Supporting bits are below, bits means second parameter of XorshiftEngine.

bits period
32 2^32 - 1
64 2^64 - 1
96 2^96 - 1
128 2^128 - 1
160 2^160 - 1
192 2^192 - 2^32

Constructors

NameDescription
this Constructs a XorshiftEngine generator seeded with x0.

Properties

NameTypeDescription
front[get] UIntTypeReturns the current number in the random sequence.
save[get] typeof(this)Captures a range state.

Methods

NameDescription
opEquals Compares against rhs for equality.
popFront Advances the random sequence.
seed (Re)seeds the generator.

Example

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

Authors

Andrei Alexandrescu Masahiro Nakagawa (Xorshift random generator) Joseph Rushton Wakeling (Algorithm D for random sampling) Ilya Yaroshenko (Mersenne Twister implementation, adapted from mir-random)

License

Boost License 1.0.