12 #if !defined(RANDOMLIB_INVERSEPIPROB_HPP)
13 #define RANDOMLIB_INVERSEPIPROB_HPP 1
106 template<
class Random>
bool prob59(
Random& r) {
109 for (
bool res =
false; ; res = !res)
110 for (
int i = 3; i--; )
if (r.
Boolean())
return res;
113 template<
class Random>
int geom4(
Random& r) {
119 template<
class Random>
bool binom(
Random& r,
int n) {
123 for (
int k = n; k--; ) d += r.
Boolean() ? 1 : -1;
124 for (
int k = n; k--; ) {
127 if (std::abs(d) > k)
return false;
142 int n = geom4(r) + geom4(r) + (prob59(r) ? 1 : 0);
143 for (
int j = 3; j--; )
if (!binom(r, n))
return false;
150 #endif // RANDOMLIB_INVERSEPIPROB_HPP
bool operator()(Random &r)
Generate random integers, reals, and booleans.
Header for Random, RandomGenerator.
Return true with probability 1/π.