Xorshift1024star

Xorshift* generators extend the basic xorshift generation mechanism by scrambling its output through multiplication by a constant factor, without touching the underlying state. The result is an extremely fast family of generators with very high-quality statistical properties.

The xorshift1024* generator offers a long (2 ^^ 1024 - 1) period, making it suitable for many massively parallel applications, while its speed and quality makes it useful as a good general purpose random number generator.

If 1024 bits of state are too much, then it is suggested to use the Xoroshiro128+ generator instead.

Constructors

this
this()
Undocumented in source.
this
this(ulong s)
this(ulong[16] s)
this(R range)

Constructor (RNG instances can only be initialized with a specified seed).

Postblit

this(this)
this(this)
Undocumented in source.

Members

Functions

dup
typeof(this) dup()

Provides a copy of this RNG instance with identical internal state.

front
ulong front()

Range primitives

jump
void jump()

Jump function, equivalent to 2 ^^ 512 calls to popFront(); can be used to generate 2 ^^ 512 non-overlapping subsequences for parallel computation.

popFront
void popFront()

Range primitives

seed
void seed(ulong s)
void seed(ulong[16] s)
void seed(R range)

(Re)seeds the generator.

Variables

empty
enum bool empty;

Range primitives

isUniformRandom
enum bool isUniformRandom;

Marks this range as a uniform random number generator

max
enum ulong max;

Largest generated value

min
enum ulong min;

Smallest generated value (0)

Examples

import std.array : array;
import std.random : isUniformRNG, randomCover, uniform;
import std.range : iota, take;
import dxorshift.xorshift1024star;

// xorshift1024* generators must be initialized
// with a specified seed
auto gen = Xorshift1024star(123456);

// verify it is indeed a uniform RNG as defined
// in the standard library, whether accessed
// directly or via a pointer
static assert(isUniformRNG!(typeof(gen)));
static assert(isUniformRNG!(typeof(&gen)));

// since the postblit is disabled, we must
// pass a pointer to any functionality that
// would otherwise copy the RNG by value
assert((&gen).take(2).array == [1060672336872339994uL,
                                1269657541839679748uL]);

// this means, of course, that we must guarantee
// the lifetime of the pointer is valid for the
// lifetime of any functionality that uses it
auto sample = iota(100).randomCover(&gen).array;

// however, we can pass the RNG as-is to any
// functionality that takes it by ref and does
// not try to copy it by value
auto val = uniform!"[]"(0.0, 1.0, gen);

// in circumstances where we really want to
// copy the RNG state, we can use `dup`
auto gen2 = gen.dup;
assert((&gen).take(6).array == (&gen2).take(6).array);

Meta

Credits

This code is ported from the public-domain reference implementation by Sebastiano Vigna, available online at http://xorshift.di.unimi.it/xorshift1024star.c

See also the research paper introducing the xorshift* family of generators: http://vigna.di.unimi.it/ftp/papers/xorshift.pdf