10 #ifndef SRC_INCLUDE_SMASH_RANDOM_H_ 
   11 #define SRC_INCLUDE_SMASH_RANDOM_H_ 
   72   static_assert(std::is_same<Engine::result_type, uint64_t>::value,
 
   73                 "experiment.cc needs the seed to be 64 bits");
 
   74   engine.seed(std::forward<T>(seed));
 
   89   return std::uniform_real_distribution<T>(min, max)(
engine);
 
  101   return std::uniform_int_distribution<T>(min, max)(
engine);
 
  112 template <
typename T = 
double>
 
  114   return std::generate_canonical<T, std::numeric_limits<double>::digits>(
 
  121 template <
typename T = 
double>
 
  124   return std::nextafter(
 
  125       std::generate_canonical<T, std::numeric_limits<double>::digits>(
engine),
 
  134 template <
typename T>
 
  148 template <
typename T = 
double>
 
  165 template <
typename T = 
double>
 
  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));
 
  189 template <
typename T>
 
  191   return (T(0) < val) - (val < T(0));
 
  202 template <
typename T = 
double>
 
  205   if (std::abs(n1) < 1E-3) {
 
  206     return xMin * std::pow(xMax / xMin, 
canonical());
 
  207   } 
else if (xMin >= 0. && xMax > 0.) {
 
  208     return std::pow(
uniform(std::pow(xMin, n1), std::pow(xMax, n1)), 1. / n1);
 
  210     return sgn(xMin) * std::pow(
uniform(std::pow(std::abs(xMin), n1),
 
  211                                         std::pow(std::abs(xMax), n1)),
 
  225 template <
typename T>
 
  227   return std::poisson_distribution<int>(lam)(
engine);
 
  237 template <
typename T>
 
  239   return std::binomial_distribution<int>(N, 
p)(
engine);
 
  249 template <
typename T>
 
  250 double normal(
const T &mean, 
const T &sigma) {
 
  251   return std::normal_distribution<double>(mean, sigma)(
engine);
 
  257 template <
typename T>
 
  281     distribution = std::discrete_distribution<>(plist.begin(), plist.end());
 
  306 template <
typename T = 
double>
 
  307 T 
cauchy(T pole, T width, T min, T max) {
 
  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);
 
  328 template <
typename T = 
double>
 
  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);
 
  350 template <
typename T = 
double>
 
  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());
 
  387   BesselSampler(
const double poisson_mean1, 
const double poisson_mean2,
 
  388                 const int fixed_difference);
 
  395   std::pair<int, int> 
sample();
 
  407   static double r_(
int n, 
double a);
 
The intention of this class is to efficiently sample  from the Bessel distribution ,...
 
double mu_
Mean of the Bessel distribution.
 
double sigma_
Standard deviation of the Bessel distribution.
 
std::pair< int, int > sample()
Sample two numbers from given Poissonians with a fixed difference.
 
const bool N_is_positive_
Boolean variable to verify that N > 0.
 
static double r_(int n, double a)
Compute the ratio of two Bessel functions r(n,a) = bessel_I(n+1,a)/bessel_I(n,a) using the continued ...
 
static constexpr double negligible_probability_
Probabilities smaller than negligibly_probability are neglected.
 
double m_
Mode of the Bessel function, see  for details.
 
static constexpr double m_switch_method_
Switching mode to normal approximation.
 
random::discrete_dist< double > dist_
Vector to store tabulated values of probabilities for small m case (m <6).
 
BesselSampler(const double poisson_mean1, const double poisson_mean2, const int fixed_difference)
Construct a BesselSampler.
 
const int N_
First parameter of Bessel distribution (=  in ).
 
const double a_
Second parameter of Bessel distribution, see  for details.
 
Discrete distribution with weight given by probability vector.
 
discrete_dist()
Default discrete distribution.
 
std::discrete_distribution distribution
The distribution object that is being used.
 
int operator()()
Draw a random number from the discrete distribution.
 
discrete_dist(const std::vector< T > &plist)
Construct from probability vector.
 
discrete_dist(std::initializer_list< T > l)
Construct from probability list.
 
void reset_weights(const std::vector< T > &plist)
Reset the discrete distribution from a new probability list.
 
int poisson(const T &lam)
Returns a Poisson distributed random number.
 
T power(T n, T xMin, T xMax)
Draws a random number according to a power-law distribution ~ x^n.
 
T exponential(T lambda)
Draws an exponentially distributed random number.
 
T beta_a0(T xmin, T b)
Draws a random number from a beta-distribution with a = 0.
 
T beta(T a, T b)
Draws a random number from a beta-distribution, where probability density of  is .
 
uniform_dist< T > make_uniform_distribution(T min, T max)
 
Engine::result_type advance()
Advance the engine's state and return the generated value.
 
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,...
 
Engine engine
The engine that is used commonly by all distributions.
 
int64_t generate_63bit_seed()
Generates a seed with a truly random 63-bit value, if possible.
 
std::mt19937_64 Engine
The random number engine used is the Mersenne Twister.
 
double normal(const T &mean, const T &sigma)
Returns a random number drawn from a normal distribution.
 
T uniform_int(T min, T max)
 
int binomial(const int N, const T &p)
Returns a binomially distributed random number.
 
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 B...
 
int sgn(T val)
Signum function.
 
void set_seed(T &&seed)
Sets the seed of the random number engine.