Random Number Generators
Contents
Random Number Generators
The following variables, functions and classes are all defined within the namespace HIPP::NUMERICAL.
Predefined Random Number Generators
The following table lists the predefined random number generator objects for quick-and-dirty
random number generation. Note that they are all static thread-local variable and all share
a global (thread-local) random engine global_random_engine with default seed,
i.e., the calling seed() of one affects the others.
Object |
Type |
Description |
|---|---|---|
standard normal dist |
||
uniform real dist in |
||
UniformRealRandomNumber<float> |
uniform real dist in |
|
UniformIntRandomNumber<char> |
uniform char in |
|
UniformIntRandomNumber<short> |
uniform short in |
|
uniform int in |
||
UniformIntRandomNumber<unsigned int> |
uniform unsigned int in |
|
UniformIntRandomNumber<long> |
uniform long in |
|
UniformIntRandomNumber<long long> |
uniform long long in |
|
UniformIntRandomNumber<std::size_t> |
uniform size_t in |
Examples:
The following codes demonstrate how to generate standard Gaussian random numbers using the predefined object randn:
using namespace HIPP;
using namespace HIPP::NUMERICAL;
/* Call the object to get a random number or a sequence of them. */
double r1 = randn(); /* return a single random number */
vector<double> r2 = randn(3); /* return a vector of 3 numbers */
double r3[3];
randn(r3, r3+3); /* fill 3 number into a range */
/* Call get() method to use different parameters. */
double r4 = randn.get(1.0, 3.0); /* a random number with mean=1, stddev=3 */
pout << r1, '\n',
r2, '\n',
pout(r3,r3+3), '\n',
r4, endl;
The output is (may depend on the implementation and variate among runs):
-0.121966
-1.08682,0.68429,-1.07519
0.0332695,0.744836,0.0336061
-0.57991
Detailed Definitions
-
static thread_local GaussianRandomNumber<> randn
Standard normal dist.
-
static thread_local UniformRealRandomNumber<> rand
Uniform real dist in [0,1].
-
static thread_local UniformRealRandomNumber<float> randfloat
Uniform real dist in [0,1], using float.
-
static thread_local UniformIntRandomNumber<char> randchar
Uniform char in [0, max char].
-
static thread_local UniformIntRandomNumber<short> randshort
Uniform short in [0, max short].
-
static thread_local UniformIntRandomNumber<> randint
Uniform int in [0, max int].
-
static thread_local UniformIntRandomNumber<unsigned int> randuint
Uniform unsigned int in [0, max unsigned int].
-
static thread_local UniformIntRandomNumber<long> randlong
Uniform long in [0, max long].
-
static thread_local UniformIntRandomNumber<long long> randlonglong
Uniform long long in [0, max long long].
-
static thread_local UniformIntRandomNumber<std::size_t> randsize
Uniform size_t in [0, max size_t].
Random Number Engines
-
class RandomEngine
Ensemble of random number engine types.
-
using minstd_rand0_t = std::minstd_rand0
-
using minstd_rand_t = std::minstd_rand
-
using mt19937_t = std::mt19937
-
using mt19937_64_t = std::mt19937_64
-
using ranlux24_base_t = std::ranlux24_base
-
using ranlux48_base_t = std::ranlux48_base
-
using ranlux24_t = std::ranlux24
-
using ranlux48_t = std::ranlux48
-
using knuth_b_t = std::knuth_b
-
using default_t = std::default_random_engine
Predefined random number generator types.
-
using device_t = std::random_device
Non-deterministic random number generator types.
-
using minstd_rand0_t = std::minstd_rand0
-
typedef RandomEngine::default_t DefaultRandomEngine
The default engine type chosen by the implementation. Generally the best in most cases.
-
static thread_local DefaultRandomEngine global_random_engine
-
static DefaultRandomEngine process_global_random_engine
The default random engine objects used by HIPP.
The thread local one is thread-safe, but threads may have the same random sequence. This is the default choice in the construction of distribution generators.
The process global one is shared among threads. It is not thread-safe and must be protected carefully.
Uniform Distributions
Uniform Distributed Integer
-
template<typename IntT = int, typename EngineT = DefaultRandomEngine>
class UniformIntRandomNumber UniformIntRandomNumber- generator of integer random numbers of uniform distribution.-
typedef IntT result_t
-
typedef EngineT engine_t
-
typedef std::uniform_int_distribution<result_t> rng_t
-
typedef typename rng_t::param_type param_t
-
typedef typename engine_t::result_type seed_t
The result type, random number engine type, underlying random number generator type, parameter type, and seed type.
-
explicit UniformIntRandomNumber(result_t a = 0, result_t b = std::numeric_limits<result_t>::max(), engine_t *engine = &global_random_engine)
-
explicit UniformIntRandomNumber(const param_t ¶m, engine_t *engine = &global_random_engine)
-
~UniformIntRandomNumber()
Constructors and destructor.
a,b: the minimum and maximum of the distribution. Instead aparam_tcan be passed.engine: an engine of random number. A pointer is passed, and its lifetime is controlled by the user.
-
UniformIntRandomNumber(const UniformIntRandomNumber &o)
-
UniformIntRandomNumber(UniformIntRandomNumber &&o)
-
UniformIntRandomNumber &operator=(const UniformIntRandomNumber &o)
-
UniformIntRandomNumber &operator=(UniformIntRandomNumber &&o)
The copy for parameter is deep, but engine is shared.
-
UniformIntRandomNumber &reset_state()
-
UniformIntRandomNumber &reset_param(result_t a = 0, result_t b = std::numeric_limits<result_t>::max())
-
UniformIntRandomNumber &reset_param(const param_t ¶m)
-
UniformIntRandomNumber &reset_engine(engine_t *engine)
-
UniformIntRandomNumber &seed(seed_t seed = engine_t::default_seed)
Setters.
reset_state(): reset the internal state so that the subsequent random numbers do not depend on the previous ones.reset_param(): reset the parameters.reset_engine(): reset the random number engine. Note that its life-time is controlled by the user.seed(): reseed the random engine.
-
result_t a() const
-
result_t b() const
-
param_t param() const
-
result_t min() const
-
result_t max() const
-
std::pair<result_t, result_t> range() const
-
engine_t *engine() const
-
rng_t &rng()
-
const rng_t &rng() const
Geters.
a(),b(): the parametera,b.param(): the packet ofaandb.min(),max(): minimum and maximum value that can be returned by the random number generator. Equal to a and b, respectively.range(): the pair{min(), max()}.engine(): the random engine.rng(): the internal random number generator.
-
result_t operator()()
-
result_t get(const param_t ¶m)
-
result_t get(result_t a, result_t b)
Get a single random number.
using current parameters.
using new parameters
param.using new parameters
aandb.
-
template<template<typename> typename Container = std::vector>
Container<result_t> operator()(std::size_t n) -
template<typename Container>
void operator()(Container &c, std::size_t n) -
template<typename InputIt>
void operator()(InputIt b, InputIt e) Get a series of random numbers.
Get
nnumbers, returned a container (must have push back).Directly pushing back into container
c(clear()is not called).Write into a range specified by a pair of iterator.
-
typedef IntT result_t
Uniform Distributed Floating-point Number
-
template<typename RealT = double, typename EngineT = DefaultRandomEngine>
class UniformRealRandomNumber UniformRealRandomNumber- generator of floating-point random numbers of uniform distribution.-
typedef RealT result_t
-
typedef EngineT engine_t
-
typedef std::uniform_real_distribution<result_t> rng_t
-
typedef typename rng_t::param_type param_t
-
typedef typename engine_t::result_type seed_t
The result type, random number engine type, underlying random number generator type, parameter type, and seed type.
-
explicit UniformRealRandomNumber(result_t a = 0., result_t b = 1., engine_t *engine = &global_random_engine)
-
explicit UniformRealRandomNumber(const param_t ¶m, engine_t *engine = &global_random_engine)
-
~UniformRealRandomNumber()
Constructors and destructor.
a,b: the minimum and maximum of the distribution. Instead aparam_tcan be passed.engine: an engine of random number. A pointer is passed, and its lifetime is controlled by the user.
-
UniformRealRandomNumber(const UniformRealRandomNumber &o)
-
UniformRealRandomNumber(UniformRealRandomNumber &&o)
-
UniformRealRandomNumber &operator=(const UniformRealRandomNumber &o)
-
UniformRealRandomNumber &operator=(UniformRealRandomNumber &&o)
The copy for parameter is deep, but engine is shared.
-
UniformRealRandomNumber &reset_state()
-
UniformRealRandomNumber &reset_param(result_t a = 0., result_t b = 1.)
-
UniformRealRandomNumber &reset_param(const param_t ¶m)
-
UniformRealRandomNumber &reset_engine(engine_t *engine)
-
UniformRealRandomNumber &seed(seed_t seed = engine_t::default_seed)
Setters.
reset_state(): reset the internal state so that the subsequent random numbers do not depend on the previous ones.reset_param(): reset the parameters.reset_engine(): reset the random number engine. Note that its life-time is controlled by the user.seed(): reseed the random engine.
-
result_t a() const
-
result_t b() const
-
param_t param() const
-
result_t min() const
-
result_t max() const
-
std::pair<result_t, result_t> range() const
-
engine_t *engine() const
-
rng_t &rng()
-
const rng_t &rng() const
Geters
a(),b(): the parametera,b.param(): the packet ofaandb.min(),max(): minimum and maximum value that can be returned by the random number generator. Equal toaandb, respectively.range(): the pair{min(), max()}.engine(): the random engine.rng(): the internal random number generator.
-
result_t operator()()
-
result_t get(const param_t ¶m)
-
result_t get(result_t a, result_t b)
Get a single random number.
using current parameters.
using new parameters
param.using new parameters
aandb.
-
template<template<typename> typename Container = std::vector>
Container<result_t> operator()(std::size_t n) -
template<typename Container>
void operator()(Container &c, std::size_t n) -
template<typename InputIt>
void operator()(InputIt b, InputIt e) Get a series of random numbers.
Get
nnumbers, returned a container (must have push back).Directly pushing back into container
c(clear()is not called).Write into a range specified by a pair of iterator.
-
typedef RealT result_t
Gaussian Random Number
-
template<typename RealT = double, typename EngineT = DefaultRandomEngine>
class GaussianRandomNumber GaussianRandomNumber- generator of Normal Distribution random numbers.-
typedef RealT result_t
-
typedef EngineT engine_t
-
typedef std::normal_distribution<result_t> rng_t
-
typedef typename rng_t::param_type param_t
-
typedef typename engine_t::result_type seed_t
-
explicit GaussianRandomNumber(result_t mean = 0., result_t stddev = 1., engine_t *engine = &global_random_engine)
-
explicit GaussianRandomNumber(const param_t ¶m, engine_t *engine = &global_random_engine)
-
~GaussianRandomNumber()
mean,stddev: parameters of normal distribution. Instead aparam_tcan be passed.engine: an engine of random number. A pointer is passed, and its lifetime is controlled by the user.
-
GaussianRandomNumber(const GaussianRandomNumber &o)
-
GaussianRandomNumber(GaussianRandomNumber &&o)
-
GaussianRandomNumber &operator=(const GaussianRandomNumber &o)
-
GaussianRandomNumber &operator=(GaussianRandomNumber &&o)
The copy for parameter is deep, but engine is shared.
-
GaussianRandomNumber &reset_state()
-
GaussianRandomNumber &reset_param(result_t mean = 0., result_t stddev = 1.)
-
GaussianRandomNumber &reset_param(const param_t ¶m)
-
GaussianRandomNumber &reset_engine(engine_t *engine)
-
GaussianRandomNumber &seed(seed_t seed = engine_t::default_seed)
Setters.
reset_state(): reset the internal state so that the subsequent random numbers do not depend on the previous ones.reset_param(): reset the parameters.reset_engine(): reset the random number engine. Note that its life-time is controlled by the user.seed(): reseed the random engine.
-
result_t mean() const
-
result_t stddev() const
-
param_t param() const
-
result_t min() const
-
result_t max() const
-
std::pair<result_t, result_t> range() const
-
engine_t *engine() const
-
rng_t &rng()
-
const rng_t &rng() const
Geters.
mean(),stddev()- the parameters of the distribution.param()- the packet ofmeanandstddev.min(),max()- minimum and maximum value that can be returned by the random number generator.range()- the pair{min(), max()}.engine()- the random engine.rng()- the internal random number generator.
-
result_t operator()()
-
result_t get(const param_t ¶m)
-
result_t get(result_t mean, result_t stddev)
Get a single random number.
using current parameters.
using new parameters
param.using new parameters
meanandstddev.
-
template<template<typename> typename Container = std::vector>
Container<result_t> operator()(std::size_t n) -
template<typename Container>
void operator()(Container &c, std::size_t n) -
template<typename InputIt>
void operator()(InputIt b, InputIt e) Get a series of random numbers.
Get
nnumbers, returned a container (must have push back).Directly pushing back into container
c(clear()is not called).Write into a range specified by a pair of iterator.
-
typedef RealT result_t
Poisson Distributions
Poisson Random Number
-
template<typename IntT = int, typename EngineT = DefaultRandomEngine>
class PoissonRandomNumber PoissonRandomNumber - generator of Poisson Distribution random number. It produces non-negative integer value \(i\), distributed according to the probability function:
\[P(i | \mu) = \exp(-\mu) \mu^i / i !,\]where \(mu\) is the mean number.
-
typedef IntT result_t
-
typedef EngineT engine_t
-
typedef std::poisson_distribution<result_t> rng_t
-
typedef typename rng_t::param_type param_t
-
typedef typename engine_t::result_type seed_t
-
explicit PoissonRandomNumber(double mean = 1.0, engine_t *engine = &global_random_engine)
-
explicit PoissonRandomNumber(const param_t ¶m, engine_t *engine = &global_random_engine)
-
~PoissonRandomNumber()
Constructors and destructor.
- Parameters
mean – parameter of Poisson distribution. Instead a
param_tcan be passed.engine – an engine of random number. A pointer is passed, and its lifetime is controlled by the user.
-
PoissonRandomNumber(const PoissonRandomNumber &o)
-
PoissonRandomNumber(PoissonRandomNumber &&o)
-
PoissonRandomNumber &operator=(const PoissonRandomNumber &o)
-
PoissonRandomNumber &operator=(PoissonRandomNumber &&o)
The copy for parameter is deep, but engine is shared.
-
PoissonRandomNumber &reset_state()
-
PoissonRandomNumber &reset_param(double mean = 1.0)
-
PoissonRandomNumber &reset_param(const param_t ¶m)
-
PoissonRandomNumber &reset_engine(engine_t *engine)
-
PoissonRandomNumber &seed(seed_t seed = engine_t::default_seed)
Setters.
reset_state(): reset the internal state so that the subsequent random numbers do not depend on the previous ones.reset_param(): reset the parameters.reset_engine(): reset the random number engine. Note that its life-time is controlled by the user.seed(): reseed the random engine.
-
double mean() const
-
param_t param() const
-
result_t min() const
-
result_t max() const
-
std::pair<result_t, result_t> range() const
-
engine_t *engine() const
-
rng_t &rng()
-
const rng_t &rng() const
Geters.
mean(): the parameter of the distribution.param(): the packet of mean.min(),max(): minimum and maximum value that can be returned by the random number generator.range(): the pair{min(), max()}.engine(): the random engine.rng(): the internal random number generator.
-
result_t operator()()
-
result_t get(const param_t ¶m)
-
result_t get(double mean)
Get a single random number.
using current parameters.
using new parameter
param.using new parameter
mean.
-
template<template<typename> typename Container = std::vector>
Container<result_t> operator()(std::size_t n) -
template<typename Container>
void operator()(Container &c, std::size_t n) -
template<typename InputIt>
void operator()(InputIt b, InputIt e) Get a series of random numbers.
Get
nnumbers, returned a container (must have push back).Directly pushing back into container
c(clear() is not called).Write into a range specified by a pair of iterator.
-
typedef IntT result_t
Exponential Random Number
-
template<typename RealT = double, typename EngineT = DefaultRandomEngine>
class ExponentialRandomNumber Non-negative floating-point value \(x\), distributed according to the exponential probability density function:
\[P(x | \lambda) = \lambda \exp(-\lambda x),\]This is the continuous counterpart of geometric distribution.
-
typedef RealT result_t
-
typedef EngineT engine_t
-
typedef std::exponential_distribution<result_t> rng_t
-
typedef typename rng_t::param_type param_t
-
typedef typename engine_t::result_type seed_t
-
explicit ExponentialRandomNumber(result_t lambda = 1.0, engine_t *engine = &global_random_engine)
-
explicit ExponentialRandomNumber(const param_t ¶m, engine_t *engine = &global_random_engine)
-
~ExponentialRandomNumber()
Constructors and destructor.
- Parameters
lambda – parameter of exponential distribution. Instead a
param_tcan be passed.engine – an engine of random number. A pointer is passed, and its lifetime is controlled by the user.
-
ExponentialRandomNumber(const ExponentialRandomNumber &o)
-
ExponentialRandomNumber(ExponentialRandomNumber &&o)
-
ExponentialRandomNumber &operator=(const ExponentialRandomNumber &o)
-
ExponentialRandomNumber &operator=(ExponentialRandomNumber &&o)
The copy for parameter is deep, but engine is shared.
-
ExponentialRandomNumber &reset_state()
-
ExponentialRandomNumber &reset_param(result_t lambda = 1.0)
-
ExponentialRandomNumber &reset_param(const param_t ¶m)
-
ExponentialRandomNumber &reset_engine(engine_t *engine)
-
ExponentialRandomNumber &seed(seed_t seed = engine_t::default_seed)
Setters.
reset_state(): reset the internal state so that the subsequent random numbers do not depend on the previous ones.reset_param(): reset the parameters.reset_engine(): reset the random number engine. Note that its life-time is controlled by the user.seed(): reseed the random engine.
-
result_t lambda() const
-
param_t param() const
-
result_t min() const
-
result_t max() const
-
std::pair<result_t, result_t> range() const
-
engine_t *engine() const
-
rng_t &rng()
-
const rng_t &rng() const
Geters.
lambda(): the parameter of the distribution.param(): the packet oflambda.min(),max(): minimum and maximum value that can be returned by the random number generator.range(): the pair{min(), max()}.engine(): the random engine.rng(): the internal random number generator.
-
result_t operator()()
-
result_t get(const param_t ¶m)
-
result_t get(result_t lambda)
Get a single random number.
using current parameters.
using new parameter
param.using new parameter
lambda.
-
template<template<typename> typename Container = std::vector>
Container<result_t> operator()(std::size_t n) -
template<typename Container>
void operator()(Container &c, std::size_t n) -
template<typename InputIt>
void operator()(InputIt b, InputIt e) Get a series of random numbers.
Get
nnumbers, returned a container (must have push back).Directly pushing back into container
c(clear()is not called).Write into a range specified by a pair of iterator.
-
typedef RealT result_t
Gamma Random Number
-
template<typename RealT = double, typename EngineT = DefaultRandomEngine>
class GammaRandomNumber Positive floating-point value \(x\), distributed according to the gamma probability density function:
\[P(x | \alpha, \beta) = \exp(- \frac{x}{\beta} ) x^{\alpha-1} / (\beta^\alpha \Gamma(\alpha) ),\]where \(\alpha\) is shape parameter and \(\beta\) the scale parameter.
-
typedef RealT result_t
-
typedef EngineT engine_t
-
typedef std::gamma_distribution<result_t> rng_t
-
typedef typename rng_t::param_type param_t
-
typedef typename engine_t::result_type seed_t
-
explicit GammaRandomNumber(result_t alpha = 1.0, result_t beta = 1.0, engine_t *engine = &global_random_engine)
-
explicit GammaRandomNumber(const param_t ¶m, engine_t *engine = &global_random_engine)
-
~GammaRandomNumber()
Constructors and destructor.
alpha,beta: parameters of gamma distribution. Instead aparam_tcan be passed.engine: an engine of random number. A pointer is passed, and its lifetime is controlled by the user.
-
GammaRandomNumber(const GammaRandomNumber &o)
-
GammaRandomNumber(GammaRandomNumber &&o)
-
GammaRandomNumber &operator=(const GammaRandomNumber &o)
-
GammaRandomNumber &operator=(GammaRandomNumber &&o)
The copy for parameter is deep, but engine is shared.
-
GammaRandomNumber &reset_state()
-
GammaRandomNumber &reset_param(result_t alpha = 1.0, result_t beta = 1.0)
-
GammaRandomNumber &reset_param(const param_t ¶m)
-
GammaRandomNumber &reset_engine(engine_t *engine)
-
GammaRandomNumber &seed(seed_t seed = engine_t::default_seed)
Setters.
reset_state(): reset the internal state so that the subsequent random numbers do not depend on the previous ones.reset_param(): reset the parameters.reset_engine(): reset the random number engine. Note that its life-time is controlled by the user.seed(): reseed the random engine.
-
result_t alpha() const
-
result_t beta() const
-
param_t param() const
-
result_t min() const
-
result_t max() const
-
std::pair<result_t, result_t> range() const
-
engine_t *engine() const
-
rng_t &rng()
-
const rng_t &rng() const
Geters.
alpha(),beta(): the parameters of the distribution.param(): the packet ofalphaandbeta.min(),max(): minimum and maximum value that can be returned by the random number generator.range(): the pair{min(), max()}.engine(): the random engine.rng(): the internal random number generator.
-
result_t operator()()
-
result_t get(const param_t ¶m)
-
result_t get(result_t alpha, result_t beta)
Get a single random number.
using current parameters.
using new parameters
param.using new parameters
alphaandbeta.
-
template<template<typename> typename Container = std::vector>
Container<result_t> operator()(std::size_t n) -
template<typename Container>
void operator()(Container &c, std::size_t n) -
template<typename InputIt>
void operator()(InputIt b, InputIt e) Get a series of random numbers.
Get
nnumbers, returned a container (must have push back).Directly pushing back into container
c(clear()is not called).Write into a range specified by a pair of iterator.
-
typedef RealT result_t
Weibull Random Number
-
template<typename RealT = double, typename EngineT = DefaultRandomEngine>
class WeibullRandomNumber Floating-point value \(x\), distributed according to the Weibull probability density function:
\[p(x | a,b) = (\frac{a}{b}) (\frac{x}{b})^{a-1} \exp( -(\frac{x}{b})^a ),\]where \(a\) is shape parameter and \(b\) the scale parameter.
-
typedef RealT result_t
-
typedef EngineT engine_t
-
typedef std::weibull_distribution<result_t> rng_t
-
typedef typename rng_t::param_type param_t
-
typedef typename engine_t::result_type seed_t
-
explicit WeibullRandomNumber(result_t a = 1.0, result_t b = 1.0, engine_t *engine = &global_random_engine)
-
explicit WeibullRandomNumber(const param_t ¶m, engine_t *engine = &global_random_engine)
-
~WeibullRandomNumber()
Constructors and destructor.
a,b: parameters of weibull distribution. Instead aparam_tcan be passed.engine: an engine of random number. A pointer is passed, and its lifetime is controlled by the user.
-
WeibullRandomNumber(const WeibullRandomNumber &o)
-
WeibullRandomNumber(WeibullRandomNumber &&o)
-
WeibullRandomNumber &operator=(const WeibullRandomNumber &o)
-
WeibullRandomNumber &operator=(WeibullRandomNumber &&o)
The copy for parameter is deep, but engine is shared.
-
WeibullRandomNumber &reset_state()
-
WeibullRandomNumber &reset_param(result_t a = 1.0, result_t b = 1.0)
-
WeibullRandomNumber &reset_param(const param_t ¶m)
-
WeibullRandomNumber &reset_engine(engine_t *engine)
-
WeibullRandomNumber &seed(seed_t seed = engine_t::default_seed)
Setters.
reset_state(): reset the internal state so that the subsequent random numbers do not depend on the previous ones.reset_param(): reset the parameters.reset_engine(): reset the random number engine. Note that its life-time is controlled by the user.seed(): reseed the random engine.
-
result_t a() const
-
result_t b() const
-
param_t param() const
-
result_t min() const
-
result_t max() const
-
std::pair<result_t, result_t> range() const
-
engine_t *engine() const
-
rng_t &rng()
-
const rng_t &rng() const
Geters.
a(),b(): the parameters of the distribution.param(): the packet ofaandb.min(),max(): minimum and maximum value that can be returned by the random number generator.range(): the pair{min(), max()}.engine(): the random engine.rng(): the internal random number generator.
-
result_t operator()()
-
result_t get(const param_t ¶m)
-
result_t get(result_t a, result_t b)
Get a single random number.
using current parameters.
using new parameters
param.using new parameters
aandb.
-
template<template<typename> typename Container = std::vector>
Container<result_t> operator()(std::size_t n) -
template<typename Container>
void operator()(Container &c, std::size_t n) -
template<typename InputIt>
void operator()(InputIt b, InputIt e) Get a series of random numbers.
Get
nnumbers, returned a container (must have push back).Directly pushing back into container
c(clear()is not called).Write into a range specified by a pair of iterator.
-
typedef RealT result_t
Extreme Value Random Number
-
template<typename RealT = double, typename EngineT = DefaultRandomEngine>
class ExtremeValueRandomNumber Floating-point value \(x\), distributed according to the extreme value (also known as Gumbel Type I, log weibull, Fisher-Tippett Type I) probability density function:
\[p(x | a,b) = \frac{1}{b} \exp( ( \frac{a-x}{b} ) - \exp( \frac{a-x}{b} ) ),\]where \(a\) is shape parameter and \(b\) the scale parameter.
-
typedef RealT result_t
-
typedef EngineT engine_t
-
typedef std::extreme_value_distribution<result_t> rng_t
-
typedef typename rng_t::param_type param_t
-
typedef typename engine_t::result_type seed_t
-
explicit ExtremeValueRandomNumber(result_t a = 0.0, result_t b = 1.0, engine_t *engine = &global_random_engine)
-
explicit ExtremeValueRandomNumber(const param_t ¶m, engine_t *engine = &global_random_engine)
-
~ExtremeValueRandomNumber()
Constructors and destructor.
a,b: parameters of extreme value distribution. Instead aparam_tcan be passed.engine: an engine of random number. A pointer is passed, and its lifetime is controlled by the user.
-
ExtremeValueRandomNumber(const ExtremeValueRandomNumber &o)
-
ExtremeValueRandomNumber(ExtremeValueRandomNumber &&o)
-
ExtremeValueRandomNumber &operator=(const ExtremeValueRandomNumber &o)
-
ExtremeValueRandomNumber &operator=(ExtremeValueRandomNumber &&o)
The copy for parameter is deep, but engine is shared.
-
ExtremeValueRandomNumber &reset_state()
-
ExtremeValueRandomNumber &reset_param(result_t a = 0.0, result_t b = 1.0)
-
ExtremeValueRandomNumber &reset_param(const param_t ¶m)
-
ExtremeValueRandomNumber &reset_engine(engine_t *engine)
-
ExtremeValueRandomNumber &seed(seed_t seed = engine_t::default_seed)
Setters.
reset_state(): reset the internal state so that the subsequent random numbers do not depend on the previous ones.reset_param(): reset the parameters.reset_engine(): reset the random number engine. Note that its life-time is controlled by the user.seed(): reseed the random engine.
-
result_t a() const
-
result_t b() const
-
param_t param() const
-
result_t min() const
-
result_t max() const
-
std::pair<result_t, result_t> range() const
-
engine_t *engine() const
-
rng_t &rng()
-
const rng_t &rng() const
Geters.
a(),b(): the parameters of the distribution.param(): the packet ofaandb.min(),max(): minimum and maximum value that can be returned by the random number generator.range(): the pair{min(), max()}.engine(): the random engine.rng(): the internal random number generator.
-
result_t operator()()
-
result_t get(const param_t ¶m)
-
result_t get(result_t a, result_t b)
Get a single random number.
using current parameters.
using new parameters
param.using new parameters
aandb.
-
template<template<typename> typename Container = std::vector>
Container<result_t> operator()(std::size_t n) -
template<typename Container>
void operator()(Container &c, std::size_t n) -
template<typename InputIt>
void operator()(InputIt b, InputIt e) Get a series of random numbers.
Get
nnumbers, returned a container (must have push back).Directly pushing back into container
c(clear()is not called).Write into a range specified by a pair of iterator.
-
typedef RealT result_t