OpenRAND
0.9
OpenRAND: A C++ Library for Reproducible Random Number Generation in Parallel Computing Environments
|
Base class for random number generators. More...
#include <base_state.h>
Public Types | |
using | result_type = uint32_t |
Public Member Functions | |
OPENRAND_DEVICE result_type | operator() () |
Generates a 32 bit unsigned integer from a uniform distribution. More... | |
template<typename T = float> | |
OPENRAND_DEVICE T | rand () |
Generates a random number from a uniform distribution between 0 and 1. More... | |
template<typename T = float> | |
OPENRAND_DEVICE T | uniform (const T low, const T high) |
Generates a number from a uniform distribution between a and b. More... | |
template<typename T = float> | |
OPENRAND_DEVICE void | fill_random (T *array, const int N) |
template<typename T = float> | |
OPENRAND_DEVICE T | randn () |
Generates a random number from a normal distribution with mean 0 and std 1. More... | |
template<typename T = float> | |
OPENRAND_DEVICE vec2< T > | randn2 () |
More efficient version of randn, returns two values at once. More... | |
template<typename T = float> | |
OPENRAND_DEVICE T | randn (const T mean, const T std_dev) |
Generates a random number from a normal distribution with mean and std. More... | |
template<bool biased = true, typename T = int> | |
OPENRAND_DEVICE T | range (const T N) |
Generates a random integer of certain range. More... | |
template<typename T = float> | |
OPENRAND_DEVICE T | gamma (T alpha, T b) |
Generates a random number from a gamma distribution with shape alpha and scale b. More... | |
template<typename T = RNG> | |
std::enable_if_t< has_counter< T >::value, RNG > | forward_state (int n) const |
Returns a new generator with the internal state forwarded by a given number. More... | |
Static Public Member Functions | |
static constexpr result_type | min () |
static constexpr result_type | max () |
Protected Member Functions | |
template<typename Ftype , typename Utype > | |
OPENRAND_DEVICE Ftype | u01 (const Utype in) const |
Base class for random number generators.
This class utilizes the CRTP pattern to inject some common functionalities into random number generators.
RNG | Random number generator class. It must contain two public methods, a constructor and a templated draw() function that returns the next 32 or 64 bit random unsigned int from its stream. |
|
inline |
Returns a new generator with the internal state forwarded by a given number.
The new generator's first output will be the n+1th output of the current generator and so on. This is O(1) operation.
n | Number of steps to move the state forward |
|
inline |
Generates a random number from a gamma distribution with shape alpha and scale b.
Adapted from the following implementation: https://www.hongliangjie.com/2012/12/19/how-to-generate-gamma-random-variables/
T | floating point type to be returned |
alpha | shape parameter of the gamma distribution |
b | scale parameter of the gamma distribution |
|
inline |
Generates a 32 bit unsigned integer from a uniform distribution.
This function is needed to conform to C++ engine interface
|
inline |
Generates a random number from a uniform distribution between 0 and 1.
T | Data type to be returned. Can be 32 or 64 bit integer, float or double. |
|
inline |
Generates a random number from a normal distribution with mean 0 and std 1.
This function implements box-muller method. This method avoids branching, and therefore more efficient on GPU. see: https://developer.nvidia.com/gpugems/gpugems3/part-vi-gpu-computing/chapter-37-efficient-random-number-generation-and-application
T | floating point type to be returned |
|
inline |
Generates a random number from a normal distribution with mean and std.
T | floating point type to be returned |
mean | mean of the normal distribution |
std_dev | standard deviation of the normal distribution |
|
inline |
More efficient version of randn, returns two values at once.
T | floating point type to be returned |
|
inline |
Generates a random integer of certain range.
This uses the method described in [1] to generate a random integer of range [0..N)
biased | if true, the faster, but slightly biased variant is used. |
T | integer type (<=32 bit) to be returned |
N | A random integral of range [0..N) will be returned |
|
inline |
Generates a number from a uniform distribution between a and b.
@Note For integer types, consider using range for greater control.
T | Data type to be returned. Can be float or double. double. |
low | lower bound of the uniform distribution |
high | upper bound of the uniform distribution |