Advanced Random Number Generators
Makes mir.random
PRNGs that satisfy Phobos std.random.isUniformRNG
also satisfy std.range.primitives.isForwardRange
. Affected PRNGs and templates:
mir.random.engine.xoshiro
: Xoshiro256StarStar
, Xoshiro128StarStar_32
, Xoroshiro128Plus
, XoshiroEngine
.mir.random.engine.pcg
: pcg32
, pcg32_oneseq
, pcg32_fast
, pcg8_once_insecure
, pcg16_once_insecure
, pcg32_once_insecure
, pcg64_once_insecure
, pcg8_oneseq_once_insecure
, pcg16_oneseq_once_insecure
, pcg32_oneseq_once_insecure
, pcg64_oneseq_once_insecure
; PermutedCongruentialEngine
as long as output_previous
is true and streamType
is not stream_t.unique
.mir.random.engine.PhobosRandom!Engine
as long as the representation of Engine
contains no pointers other than function pointers and its opCall()
and destructor (if any) are @safe
and pure
. All PRNGs defined in mir.random
meet these conditions.Prior to this the only mir.random
PRNGs that implemented .save
were mir.random.engine.splitmix.SplitMix64
and Splittable64
.
randomSlice
was added to mir.random.algorithm
field
API rework for complex numbersrne
was added to some algorithmsMost of the API is duplicated to be used with default thread-local random engine. See also the first example in the README.
We now use Daniel Lemire's fast alternative to modulo reduction. Compiling with LDC 1.6.0 for x86-64, Mt19937_64 randIndex
throughput increased 40% for uint and 136% for ulong. Xoroshiro128Plus randIndex
throughput increased 73% for uint and 325% for ulong.
The required mir-algorithm version has increased to v0.7.0 because extMul is necessary for the ulong version.
rne
(like std.random rndGen
); threadLocal!Engine
for arbitrary engine; & ways of mucking about with the bookkeeping state that most people won't need but a few have requested in the past.@safe
.GETRANDOM
in unpredictableSeed
now works on non-x86/x86-64 architectures.genRandomBlocking
/genRandomNonBlocking
that take a pointer and a length are no longer @trusted
. Instead there are trusted overloads for both that take a ubyte[]
.mir.random.algorithm
has been changed in the interest of memory safety. You can still write unsafe code but now if you try to write @safe
code the library will let you. Instead of taking engines by reference and storing their addresses (which could result in the stored address outliving the engine), instead the various functions require arguments to be either objects or pointers to structs. For local-scoped engines there are templates with alias parameters. This is a major API change so feedback/criticism is welcome.mir.random.engine.xorshift : Xorshift1024StarPhi, Xoroshiro128Plus
)Mt19937
and Mt19937_64
can be seeded from array or ndslicemir.random.engine.preferHighBits!T
to query new optional enum preferHighBits
unpredictableSeed
and genRandomNonBlocking
.isSaturatedRandomEngine!T
not working when T.opCall
is a function template.genRandomNonBlocking
and genRandomBlocking
was added to mir.random.engine
by Sebastian Wilzbach (@wilzbach). unpredictableSeed
became more secure.Random
alias).SphereVariable
, SimplexVariable
, DirichletVariable
, and MultivariateNormalVariable
was added to mir.random.ndvariable
by Simon Bürger (@krox). Multivariate normal RNG uses private Cholesky decomposition, which has not unittests yet. PRs are welcome.