Implements algorithms that transform the output of uniform random number generators into other random behaviours, such as shuffling, sampling, and so on. Typically these are implemented as range objects that wrap a provided RNG instance.
Provides access to non-deterministic sources of randomness. These are implemented as Input Ranges and in many cases are architecture- or OS-dependent.
Implements algorithms for generating random numbers drawn from different statistical distributions. Where possible, each random distribution is provided in two different forms:
Implements algorithms for uniform pseudo-random number generation. Following the definition used in the C++11 Standard Template Library $(LESS)_random$(GREATER) header, a uniform random number generator is defined to be an Input Range whose values are unsigned integer values drawn from the closed interval [min, max], such that each value among the possible set of results has (ideally) equal probability of being next in the sequence. Pseudo-random number generators are typically implemented as Forward Ranges, but this is not a requirement.
Implements compile-time checks for different features of random number generating code.
See Source File
$(HAPSRC hap/_random/package.d)
© 2008-2011 Andrei Alexandrescu, 2013 Chris Cain, 2013 Andrej Mitrović, 2011 Masahiro Nakagawa, 2012-2014 Joseph Rushton Wakeling
hap._random is a random number generation library for the D programming language. It is intended as a replacement for Phobos’ std._random, and addresses a number of issues encountered in that module: in particular, hap._random implements random number generators and related entities as reference types rather than value types, which avoids a number of problems that can arise with the standard library RNGs. It is however largely derivative of std._random and to the greatest extent possible implements the same API, with some functional additions, notably the random distribution ranges.
The library name, hap, is Welsh for “random” or “chance”. :-)
The functionality implemented by this package is divided into four different groups:
The hap._random package will import all of the above functionality. Alternatively, individual modules can be imported as required.
Experimental functionality, not fully developed but available as a technology preview, includes:
This functionality will not be imported as part of the main hap._random package but can be imported via the individual modules. It should be used with some caution, as its API may change significantly in future releases.
Migration: To use hap._random instead of std._random it should suffice to:
Note: Currently only one function is known to produce different behaviour to its std._random counterpart: hap._random.distribution.dice uses a different algorithm to std._random.dice.
Warning: Bear in mind that non-reference-type RNGs used in conjunction with this package will almost certainly generate erroneous results. In particular this package should not be used together with std._random itself.