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)
68 assert(lower_bound <= upper_bound);
77 int r = (int)floor(
uniformReal((S)lower_bound, (S)(upper_bound) + 1.0));
79 return (r > upper_bound) ? upper_bound :
r;
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>
125 (S)r_min, (S)(r_max) + 1.0, focus));
127 return (r > r_max) ? r_max :
r;
131 template <
typename S>
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>
158 template <
typename S>
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)
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>
void quaternion(S value[4])
Uniform random unit quaternion sampling. The computed value has the order (x,y,z,w) ...
template class FCL_EXPORT RNG< double >
void ball(S r_min, S r_max, S &x, S &y, S &z)
Uniform random sample in a ball with radius from r_min to r_max.
static bool isFirstSeedGenerated()
S uniformReal(S lower_bound, S upper_bound)
Generate a random real within given bounds: [lower_bound, upper_bound)
RNG()
Constructor. Always sets a different random seed.
static std::uint_fast32_t getSeed()
Get the seed used for random number generation. Passing the returned value to setSeed() at a subseque...
void disk(S r_min, S r_max, S &x, S &y)
Uniform random sample on a disk with radius from r_min to r_max.
std::uniform_real_distribution uniDist_
*void eulerRPY(S value[3])
Uniform random sampling of Euler roll-pitch-yaw angles, each in the range [-pi, pi). The computed value has the order (roll, pitch, yaw)
S halfNormalReal(S r_min, S r_max, S focus=3.0)
Generate a random real using a half-normal distribution. The value is within specified bounds [r_min...
S gaussian(S mean, S stddev)
Generate a random real using a normal distribution with given mean and variance.
static constexpr S pi()
The mathematical constant pi.
int uniformInt(int lower_bound, int upper_bound)
Generate a random integer within given bounds: [lower_bound, upper_bound].
int halfNormalInt(int r_min, int r_max, S focus=3.0)
Generate a random integer using a half-normal distribution. The value is within specified bounds ([r_...
S uniform01()
Generate a random real between 0 and 1.
bool uniformBool()
Generate a random boolean.
static std::uint_fast32_t getFirstSeed()
static void setSeed(std::uint_fast32_t seed)
Set the seed for random number generation. Use this function to ensure the same sequence of random nu...
S gaussian01()
Generate a random real using a normal distribution with mean 0 and variance 1.
static void setUserSetSeed(std::uint_fast32_t seed)
std::normal_distribution normalDist_