|
int64_t | generate_63bit_seed () |
| Generates a seed with a truly random 63-bit value, if possible. More...
|
|
template<typename T > |
void | set_seed (T &&seed) |
| Sets the seed of the random number engine. More...
|
|
Engine::result_type | advance () |
| Advance the engine's state and return the generated value. More...
|
|
template<typename T > |
T | uniform (T min, T max) |
|
template<typename T > |
T | uniform_int (T min, T max) |
|
template<typename T = double> |
T | canonical () |
|
template<typename T = double> |
T | canonical_nonzero () |
|
template<typename T > |
uniform_dist< T > | make_uniform_distribution (T min, T max) |
|
template<typename T = double> |
T | exponential (T lambda) |
| Draws an exponentially distributed random number. More...
|
|
template<typename T = double> |
T | expo (T A, T x1, T x2) |
| Draws a random number x from an exponential distribution exp(A*x), where A is assumed to be positive, and x is typically negative. More...
|
|
template<typename T > |
int | sgn (T val) |
| Signum function. More...
|
|
template<typename T = double> |
T | power (T n, T xMin, T xMax) |
| Draws a random number according to a power-law distribution ~ x^n. More...
|
|
template<typename T > |
int | poisson (const T &lam) |
| Returns a Poisson distributed random number. More...
|
|
template<typename T > |
int | binomial (const int N, const T &p) |
| Returns a binomially distributed random number. More...
|
|
template<typename T > |
double | normal (const T &mean, const T &sigma) |
| Returns a random number drawn from a normal distribution. More...
|
|
template<typename T = double> |
T | cauchy (T pole, T width, T min, T max) |
| Draws a random number from a Cauchy distribution (sometimes also called Lorentz or non-relativistic Breit-Wigner distribution) with the given parameters (constant width!) inside the range [min,max]. More...
|
|
template<typename T = double> |
T | beta (T a, T b) |
| Draws a random number from a beta-distribution, where probability density of \(x\) is \(p(x) = frac{\Gamma(a)\Gamma(b)}{Gamma(a+b)} x^{a-1} (1-x)^{b-1}\). More...
|
|
template<typename T = double> |
T | beta_a0 (T xmin, T b) |
| Draws a random number from a beta-distribution with a = 0. More...
|
|
Namespace random provides functions for random Number Generation.
template<typename T = double>
T smash::random::expo |
( |
T |
A, |
|
|
T |
x1, |
|
|
T |
x2 |
|
) |
| |
Draws a random number x from an exponential distribution exp(A*x), where A is assumed to be positive, and x is typically negative.
The result x is restricted to lie between x1 and x2 (with x2 < x <= x1).
- Parameters
-
A | Positive shape parameter. |
x1 | Maximal sampled value. |
x2 | Minimal sampled value. |
- Returns
- Sampled random number.
Definition at line 166 of file random.h.
167 const T a1 = A * x1, a2 = A * x2;
168 const T a_min = std::log(std::numeric_limits<T>::min());
170 assert(A > T(0.) && x1 >= x2 && a1 > a_min);
172 const T r1 = std::exp(a1);
173 const T r2 = a2 > a_min ? std::exp(a2) : T(0.);
178 x = std::log(
uniform(r1, r2)) / A;
179 }
while (!(x <= x1 && x > x2));
template<typename T = double>
T smash::random::cauchy |
( |
T |
pole, |
|
|
T |
width, |
|
|
T |
min, |
|
|
T |
max |
|
) |
| |
Draws a random number from a Cauchy distribution (sometimes also called Lorentz or non-relativistic Breit-Wigner distribution) with the given parameters (constant width!) inside the range [min,max].
This function is similar to std::cauchy_distribution, but can return values inside a limited interval.
- Parameters
-
pole | Pole parameter of the Cauchy function, i.e. location of the peak. |
width | Width parameter of the Cauchy function, determining the sharpness of the peak. |
min | Minimum value to be returned. |
max | Maximum value to be returned. |
- Returns
- Sampled random number.
Definition at line 307 of file random.h.
311 const double u_min = std::atan((min - pole) / width);
312 const double u_max = std::atan((max - pole) / width);
313 const double u =
uniform(u_min, u_max);
314 return pole + width * std::tan(u);
template<typename T = double>
T smash::random::beta |
( |
T |
a, |
|
|
T |
b |
|
) |
| |
Draws a random number from a beta-distribution, where probability density of \(x\) is \(p(x) = frac{\Gamma(a)\Gamma(b)}{Gamma(a+b)} x^{a-1} (1-x)^{b-1}\).
This distribution is necessary for string formation. The implementation uses a property connecting beta distribution to gamma-distribution. Interchanging a and b will not change results.
- Parameters
-
a | Shape parameter. |
b | Scale parameter. |
- Returns
- Sampled random number.
Definition at line 329 of file random.h.
331 assert(a > T(0.0) && b > T(0.0));
332 const T x1 = std::gamma_distribution<T>(a)(
engine);
333 const T x2 = std::gamma_distribution<T>(b)(
engine);
334 return x1 / (x1 + x2);
template<typename T = double>
T smash::random::beta_a0 |
( |
T |
xmin, |
|
|
T |
b |
|
) |
| |
Draws a random number from a beta-distribution with a = 0.
In this case the probability density is \(p(x) = 1/x (1-x)^b\). The integral from 0 to 1 over this distribution diverges, so the sampling is performed in the interval (xmin, 1). This distribution is necessary for string formation. The implementation uses the following property: \(p(x)dx = dx/x (1-x)^b = (1-x)^b d ln(x) = (1 - e^{-y})^b dy\), where \( y = - ln(x) \).
- Parameters
-
xmin | Minimal sampled value. |
b | Second shape parameter. |
- Returns
- Sampled random number.
Definition at line 351 of file random.h.
352 assert(xmin > T(0.0) && xmin < T(1.0));
355 y =
uniform(0.0, -std::log(xmin));
356 }
while (std::pow((1.0 - std::exp(-y)), b) <
canonical());