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;
}- Does not depend on DRuntime (Better C concept)
- Mir Random
rand!float/rand!double/rand!realgenerates saturated real random numbers in(-1, 1). For example,rand!realcan produce more than 2^78 unique numbers. In other hand,std.random.uniform01!realproduces less than2^31unique numbers with default Engine. - Mir Random fixes Phobos integer underflow bugs.
- Additional optimization was added for enumerated types.
- Random nd-array (ndslice) generation.
- Bounded integer generation in
randIndexuses Daniel Lemire's fast alternative to modulo reduction. The throughput increase measured forrandIndex!uinton an x86-64 processor compiled with LDC 1.6.0 was 1.40x forMt19937_64and 1.73x forXoroshiro128Plus. The throughput increase measured forrandIndex!ulongwas 2.36x forMt19937_64and 4.25x forXoroshiro128Plus.
- Uniform
- Exponential
- Gamma
- Normal
- Cauchy
- ...
- Simplex
- Sphere
- Multivariate Normal
- ...
- Ndslice and range API adaptors
opCallAPI instead of range interface is used (similar to C++)- No default and copy constructors are allowed for generators.
unpredictableSeedhas not state, returnssize_tunpredictableSeed!UIntTypeoverload for seeds of any unsigned type (merged to Phobos)- Any unsigned generators are allowed.
minproperty was removed. Any integer generator can normalize its minimum down to zero.- Mt19937: +100% performance for initialization. (merged to Phobos)
- Mt19937: +54% performance for generation. (merged to Phobos)
- Mt19937: fixed to be more CPU cache friendly. (merged to Phobos)
- 64-bit Mt19937 initialization is fixed (merged to Phobos)
- 64-bit Mt19937 is default for 64-bit targets
- Permuted Congruential Generators (new)
- SplitMix generators (new)
- Fixed XorshiftEngine's support for non-
uintword sizes & allow various shift directions (merged to Phobos) - XorshiftStar Generators (new)
- Xoroshiro128Plus generator (new)
- Xoshiro256StarStar & Xoshiro128StarStar_32 generators (new)