A class for (pseudo) random number generation. More...
#include <marvin_Random.h>
Public Member Functions | |
RandomGenerator (std::random_device &rd) | |
template<NumericType T> | |
T | generate (Range< T > range) noexcept |
A class for (pseudo) random number generation.
This class is a wrapper around the usual modern c++ random approach, with a templated Engine type. Below is a copy pasted excerpt from the cppreference information about the random engine types: number of trade-offs:
The linear congruential engine (std::minstd_rand
, std::minstd_rand0
) is moderately fast and has a very small storage requirement for state.
The Mersenne twister engine (std::mt19937
, std::mt19937_64) is slower and has greater state storage requirements but with the right parameters has the longest non-repeating sequence with the most desirable spectral characteristics (for a given definition of desirable).<br> The subtract with carry engine (
std::ranlux24_base, std::ranlux48_base
) is very fast even on processors without advanced arithmetic instruction sets, at the expense of greater state storage and sometimes less desirable spectral characteristics.
|
explicit |
As it's not recommended to have multiple copies of a std::random_device
, this class relies on one to be provided to its constructor, which is used to configure the internal std::mt19937
rng.
rd | An instance of a std::random_device to seed the internal rng with. |
|
inlinenodiscardnoexcept |
Generates a (pseudo) random number in the given Range. Internally uses the appropriate std::uniform_t_distribution
depending on if T is an integral type, or a float-type.
range | An instance of the Range POD type, specifying the min and max values the rng should generate between. |
range
.