MostlyHarmless 0.0.1
 
Loading...
Searching...
No Matches
marvin::utils::RandomGenerator< Engine > Class Template Referencefinal

A class for (pseudo) random number generation. More...

#include <marvin_Random.h>

Public Member Functions

 RandomGenerator (std::random_device &rd)
 
template<NumericType T>
generate (Range< T > range) noexcept
 

Detailed Description

template<RandomEngineType Engine>
class marvin::utils::RandomGenerator< Engine >

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.

Constructor & Destructor Documentation

◆ RandomGenerator()

template<RandomEngineType Engine>
marvin::utils::RandomGenerator< Engine >::RandomGenerator ( std::random_device & rd)
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.

Parameters
rdAn instance of a std::random_device to seed the internal rng with.

Member Function Documentation

◆ generate()

template<RandomEngineType Engine>
template<NumericType T>
T marvin::utils::RandomGenerator< Engine >::generate ( Range< T > range)
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.

Parameters
rangeAn instance of the Range POD type, specifying the min and max values the rng should generate between.
Returns
A pseudo random number in range.

The documentation for this class was generated from the following file: