10 #if !defined(EXRANDOM_UNIT_NORMAL_DIST_HPP) 11 #define EXRANDOM_UNIT_NORMAL_DIST_HPP 1 52 template<
typename Generator>
56 k = S(k);
if (k < 0)
continue;
58 int j = k;
while (j-- && E(g, x)) {};
59 if (!(j < 0))
continue;
60 if (!B(g, x))
continue;
62 if (_y.init().less_than_half(g)) x.
negate();
75 template<
typename RealType,
typename Generator>
78 return _x.template value<RealType>(g);
89 static const uint_t
base = digit_gen::base;
91 static const int bits = digit_gen::bits;
92 static const bool power_of_two = digit_gen::power_of_two;
99 template<
typename Generator>
100 bool H(Generator& g) {
101 if (!_y.
init().less_than_half(g))
return true;
103 if (!_z.
init().less_than(g, _y))
return false;
104 if (!_y.
init().less_than(g, _z))
return true;
109 template<
typename Generator>
111 {
int n = 0;
while (H(g)) ++n;
return n; }
115 for (
int k = 0, k2 = 0; k2 <= n; ++k, k2 += 2*k - 1) {
117 if (n == k2)
return k;
123 template<
typename Generator>
124 bool E(Generator& g, u_rand<digit_gen>& x) {
125 if (!_y.
init().less_than(g, x))
return true;
127 if (!_z.
init().less_than(g, _y))
return false;
128 if (!_y.
init().less_than(g, _z))
return true;
133 template<
typename Generator>
134 bool B(Generator& g, u_rand<digit_gen>& x) {
137 if (_z.
init().less_than_half(g))
break;
138 if (!_z.
init().less_than(g, n ? _y : x))
break;
139 if (!_y.
init().less_than(g, x))
break;
149 #endif // EXRANDOM_UNIT_NORMAL_DIST_HPP Sample u-rands exactly from the unit normal distribution.
digit_gen & digit_generator() const
RealType value(Generator &g)
void generate(Generator &g, u_rand< digit_gen > &x)
unit_normal_dist(digit_gen &D)
The machinery to handle u-rands, arbitrary precision random deviates.
void set_integer(unsigned n)