File rng.hpp¶
Class for holding different random number generators.
- Author
- Oliver W. Laslett
-
class
Rng
¶ - #include <rng.hpp>
Abstract class for random number generators.
Subclassed by RngArray, RngMtDownsample, RngMtNorm
Public Functions
-
virtual double
get
() = 0¶ Get a single random number.
- Return
- a single draw from the random number generator
-
virtual double
-
class
RngMtNorm
¶ - #include <rng.hpp>
Uses Mersenne Twister to generate normally distributed values.
Random numbers have a mean of zero and a user specified standard deviation.
Inherits from Rng
Public Functions
-
RngMtNorm
(const unsigned long int seed, const double std)¶ Default constructor for RngMtNorm.
- Parameters
seed
: seed for random number generatorstd
: the standard deviation of the normally distributed numbers
-
double
get
()¶ Draw a single normally distributed value from the RNG.
- Return
- single normally distributed number
-
-
class
RngMtDownsample
¶ - #include <rng.hpp>
Generate normally distributed values with downsampling.
Uses the Mersenne Twister to generate normally distributed random numbers. Down-samples the stream of random numbers by summing consecutive draws along each dimension. Function is usually used for generating coarse Wiener processes
Inherits from Rng
Public Functions
-
RngMtDownsample
(const unsigned long int seed, const double std, const size_t dim, const size_t down_factor)¶ Default constructor for RngMtDownsample.
-
double
get
()¶ Get a single downsampled value from the random number generator.
Private Functions
-
void
downsample_draw
()¶
Private Members
-
std::mt19937_64
generator
¶ A Mersenne Twister generator instance.
-
std::normal_distribution<double>
dist
¶ A normal distribution instance.
-
size_t
current_dim
¶ Stores the current state of the output dimenstion.
-
std::vector<double>
store
¶ Stores consecutive random numbers.
-
const size_t
D
¶ The number of dimensions required.
-
const size_t
F
¶ The number of consecutive random numbers to downsample.
-
-
class
RngArray
¶ - #include <rng.hpp>
Provides an
Rng
interface to a predefined array of numbers.Inherits from Rng
Public Functions
-
RngArray
(const double *arr, size_t arr_length, size_t stride = 1)¶ Default constructor for RngArray.
- Parameters
_arr
: a predefined array of random numbers_arr_length
: length of the predefined array_stride
: the number of consecutive elements to stride for each call to.get()
-
double
get
()¶ Get the next (possibly stridden) value from the array.
The first call will always return the value at the 0th index. Each subsequent call will stride the array (default value is 1) and return that value. A call that extends beyond the end of the array will result in an error.
- Exceptions
std::out_of_range
: when a call attempts to get a value beyond the maximum length of the predefined array.
-