32 #ifndef SHARK_CORE_RANDOM_H 33 #define SHARK_CORE_RANDOM_H 42 typedef std::mt19937 rng_type;
47 template<
class RngType>
48 bool coinToss(RngType& rng,
double pHeads = 0.5){
49 std::bernoulli_distribution dist(pHeads);
54 template<
class RngType>
55 double uni(RngType& rng,
double lower = 0.0,
double upper = 1.0){
56 std::uniform_real_distribution<double> dist(lower,upper);
61 template<
class RngType,
class T>
63 std::uniform_int_distribution<T> dist(low, high);
68 template<
class RngType>
70 std::normal_distribution<double> dist(
mean,std::sqrt(
variance));
75 template<
class RngType>
76 double logNormal(RngType& rng,
double m = 0.0,
double v = 1.0){
77 return std::exp(
gauss(rng,m,v));
84 template<
class RngType>
85 double truncExp(RngType& rng,
double lambda,
double maximum,
double Z = -1.0){
86 double y =
uni(rng,0.0,maximum);
91 Z = 1-std::exp(-lambda*maximum);
92 return - std::log(1. - y*Z)/
lambda;