Advanced Random Number Generators
Advanced Random Number Generators
Documentation - http://mir-random.libmir.org/
This library is for general-purpose random number generation. Do not use it for cryptography or secret generation.
void main()
{
import mir.random;
import mir.random.variable: normalVar;
import mir.random.algorithm: randomSlice;
auto sample = normalVar.randomSlice(10);
import std.stdio;
sample[$.randIndex].writeln;
}
void main()
{
import mir.random;
import mir.random.variable: normalVar;
import mir.random.algorithm: randomSlice;
// Engines are allocated on stack or global
auto rng = Random(unpredictableSeed);
auto sample = rng.randomSlice(normalVar, 10);
import std.stdio;
sample[rng.randIndex($)].writeln;
}
random
(new implementation and API)rand!float
/rand!double
/rand!real
generates saturated real random numbers in (-1, 1)
. For example, rand!real
can produce more than 2^78 unique numbers. In other hand, std.random.uniform01!real
produces less than 2^31
unique numbers with default Engine.randIndex
uses Daniel Lemire's fast alternative to modulo reduction. The throughput increase measured for randIndex!uint
on an x86-64 processor compiled with LDC 1.6.0 was 1.40x for Mt19937_64
and 1.73x for Xoroshiro128Plus
. The throughput increase measured for randIndex!ulong
was 2.36x for Mt19937_64
and 4.25x for Xoroshiro128Plus
.random.variable
(new)random.ndvariable
(new)random.algorithm
(new)random.engine.*
(fixed, reworked, new)opCall
API instead of range interface is used (similar to C++)unpredictableSeed
has not state, returns size_t
unpredictableSeed!UIntType
overload for seeds of any unsigned type (merged to Phobos)min
property was removed. Any integer generator can normalize its minimum down to zero.uint
word sizes & allow various shift directions (merged to Phobos)