A disabled default is present on this object. To use it, use one of the other constructors or a factory function.
Constructor (RNG instances can only be initialized with a specified seed).
Copying this object is disabled.
A postblit is present on this object, but not explicitly documented in the source.
Provides a copy of this RNG instance with identical internal state.
Range primitives
Jump function, equivalent to 2 ^^ 64 calls to popFront(); can be used to generate 2 ^^ 64 non-overlapping subsequences for parallel computation.
Range primitives
(Re)seeds the generator.
Range primitives
Marks this range as a uniform random number generator
Largest generated value
Smallest generated value (0)
1 import std.array : array; 2 import std.random : isUniformRNG, randomSample, uniform; 3 import std.range : iota, take; 4 import dxorshift.xoroshiro128plus; 5 6 // xoroshiro128+ generators must be initialized 7 // with a specified seed 8 auto gen = Xoroshiro128plus(123456); 9 10 // verify it is indeed a uniform RNG as defined 11 // in the standard library, whether accessed 12 // directly or via a pointer 13 static assert(isUniformRNG!(typeof(gen))); 14 static assert(isUniformRNG!(typeof(&gen))); 15 16 // since the postblit is disabled, we must 17 // pass a pointer to any functionality that 18 // would otherwise copy the RNG by value 19 assert((&gen).take(2).array == [14854895758870614632uL, 20 2102156639392820999uL]); 21 22 // this means, of course, that we must guarantee 23 // the lifetime of the pointer is valid for the 24 // lifetime of any functionality that uses it 25 auto sample = iota(100).randomSample(10, &gen).array; 26 27 // however, we can pass the RNG as-is to any 28 // functionality that takes it by ref and does 29 // not try to copy it by value 30 auto val = uniform!"(]"(3.5, 4.0, gen); 31 32 // in circumstances where we really want to 33 // copy the RNG state, we can use `dup` 34 auto gen2 = gen.dup; 35 assert((&gen).take(9).array == (&gen2).take(9).array);
This code is ported from the public-domain reference implementation by David Blackman and Sebastiano Vigna, available online at http://xorshift.di.unimi.it/xoroshiro128plus.c
The xoroshiro128+ uniform random number generator is the fastest full-period generator passing the BigCrush test suite without systematic failures.
Due to the relatively short period (2 ^^ 128 - 1) it is acceptable only for applications with a mild amount of parallelism; for applications requiring many parallel random sequences, Xorshift1024star is recommended instead.
Besides passing BigCrush, this generator passes the PractRand test suite up to (and including) 16TB, with the exception of binary rank tests, which fail due to the lowest bit being a linear feedback shift register (LFSR). All other bits pass all tests.