38 #ifndef FCL_MATH_RNG_INL_H
39 #define FCL_MATH_RNG_INL_H
53 : generator_(detail::Seed::getNextSeed()), uniDist_(0, 1), normalDist_(0, 1)
61 return uniDist_(generator_);
68 assert(lower_bound <= upper_bound);
70 return (upper_bound - lower_bound) * uniDist_(generator_) + lower_bound;
77 int r = (int)floor(uniformReal((S)lower_bound, (S)(upper_bound) + 1.0));
79 return (
r > upper_bound) ? upper_bound :
r;
86 return uniDist_(generator_) <= 0.5;
93 return normalDist_(generator_);
100 return normalDist_(generator_) * stddev + mean;
104 template <
typename S>
107 assert(r_min <= r_max);
109 const auto mean = r_max - r_min;
110 auto v = gaussian(mean, mean / focus);
115 auto r = v >= 0.0 ? v + r_min : r_min;
117 return r > r_max ? r_max :
r;
121 template <
typename S>
124 int r = (int)std::floor(halfNormalReal(
125 (S)r_min, (S)(r_max) + 1.0, focus));
127 return (
r > r_max) ? r_max :
r;
131 template <
typename S>
134 auto x0 = uniDist_(generator_);
135 auto r1 = std::sqrt(1.0 - x0), r2 = std::sqrt(x0);
138 auto c1 = std::cos(t1);
139 auto s1 = std::sin(t1);
140 auto c2 = std::cos(t2);
141 auto s2 = std::sin(t2);
149 template <
typename S>
153 value[1] = std::acos(1.0 - 2.0 * uniDist_(generator_)) -
constants<S>::pi() / 2.0;
158 template <
typename S>
161 auto a = uniform01();
162 auto b = uniform01();
163 auto r = std::sqrt(a * r_max * r_max + (1 - a) * r_min * r_min);
165 x =
r * std::cos(theta);
166 y =
r * std::sin(theta);
170 template <
typename S>
172 S r_min, S r_max, S& x, S& y, S& z)
174 auto a = uniform01();
175 auto b = uniform01();
176 auto c = uniform01();
177 auto r = std::pow(a*std::pow(r_max, 3) + (1 - a)*std::pow(r_min, 3), 1/3.0);
178 auto theta = std::acos(1 - 2 * b);
181 auto costheta = std::cos(theta);
182 auto sintheta = std::sin(theta);
183 auto cosphi = std::cos(phi);
184 auto sinphi = std::sin(phi);
186 y =
r * sintheta * cosphi;
187 z =
r * sintheta * sinphi;
191 template <
typename S>
196 std::cerr <<
"Random number generation already started. Changing seed now "
197 <<
"will not lead to deterministic sampling.\n";
202 std::cerr <<
"Random generator seed cannot be 0. Using 1 instead.\n";
212 template <
typename S>