Random number generation. More...
#include <hpp/fcl/math/sampling.h>
Public Member Functions | |
RNG () | |
Constructor. Always sets a different random seed. More... | |
double | uniform01 () |
Generate a random real between 0 and 1. More... | |
double | uniformReal (double lower_bound, double upper_bound) |
Generate a random real within given bounds: [lower_bound, upper_bound) More... | |
int | uniformInt (int lower_bound, int upper_bound) |
Generate a random integer within given bounds: [lower_bound, upper_bound]. More... | |
bool | uniformBool () |
Generate a random boolean. More... | |
double | gaussian01 () |
Generate a random real using a normal distribution with mean 0 and variance 1. More... | |
double | gaussian (double mean, double stddev) |
Generate a random real using a normal distribution with given mean and variance. More... | |
double | halfNormalReal (double r_min, double r_max, double focus=3.0) |
Generate a random real using a half-normal distribution. The value is within specified bounds [r_min, r_max], but with a bias towards r_max. The function is implemended using a Gaussian distribution with mean at r_max - r_min. The distribution is 'folded' around r_max axis towards r_min. The variance of the distribution is (r_max - r_min) / focus. The higher the focus, the more probable it is that generated numbers are close to r_max. More... | |
int | halfNormalInt (int r_min, int r_max, double focus=3.0) |
Generate a random integer using a half-normal distribution. The value is within specified bounds ([r_min, r_max]), but with a bias towards r_max. The function is implemented on top of halfNormalReal() More... | |
void | quaternion (double value[4]) |
Uniform random unit quaternion sampling. The computed value has the order (x,y,z,w) More... | |
void | eulerRPY (double 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) */. More... | |
void | disk (double r_min, double r_max, double &x, double &y) |
Uniform random sample on a disk with radius from r_min to r_max. More... | |
void | ball (double r_min, double r_max, double &x, double &y, double &z) |
Uniform random sample in a ball with radius from r_min to r_max. More... | |
Static Public Member Functions | |
static void | setSeed (boost::uint32_t seed) |
Set the seed for random number generation. Use this function to ensure the same sequence of random numbers is generated. More... | |
static boost::uint32_t | getSeed () |
Get the seed used for random number generation. Passing the returned value to setSeed() at a subsequent execution of the code will ensure deterministic (repeatable) behaviour. Useful for debugging. More... | |
Random number generation.
An instance of this class cannot be used by multiple threads at once (member functions are not const). However, the constructor is thread safe and different instances can be used safely in any number of threads. It is also guaranteed that all created instances will have a different random seed.
fcl::RNG::RNG | ( | ) |
Constructor. Always sets a different random seed.
void fcl::RNG::ball | ( | double | r_min, |
double | r_max, | ||
double & | x, | ||
double & | y, | ||
double & | z | ||
) |
Uniform random sample in a ball with radius from r_min to r_max.
Referenced by fcl::SamplerSE3Euler_ball::sample(), and fcl::SamplerSE3Quat_ball::sample().
void fcl::RNG::disk | ( | double | r_min, |
double | r_max, | ||
double & | x, | ||
double & | y | ||
) |
Uniform random sample on a disk with radius from r_min to r_max.
Referenced by fcl::SamplerSE2_disk::sample().
void fcl::RNG::eulerRPY | ( | double | 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) */.
|
inline |
Generate a random real using a normal distribution with given mean and variance.
|
inline |
Generate a random real using a normal distribution with mean 0 and variance 1.
|
static |
Get the seed used for random number generation. Passing the returned value to setSeed() at a subsequent execution of the code will ensure deterministic (repeatable) behaviour. Useful for debugging.
int fcl::RNG::halfNormalInt | ( | int | r_min, |
int | r_max, | ||
double | focus = 3.0 |
||
) |
Generate a random integer using a half-normal distribution. The value is within specified bounds ([r_min, r_max]), but with a bias towards r_max. The function is implemented on top of halfNormalReal()
double fcl::RNG::halfNormalReal | ( | double | r_min, |
double | r_max, | ||
double | focus = 3.0 |
||
) |
Generate a random real using a half-normal distribution. The value is within specified bounds [r_min, r_max], but with a bias towards r_max. The function is implemended using a Gaussian distribution with mean at r_max - r_min. The distribution is 'folded' around r_max axis towards r_min. The variance of the distribution is (r_max - r_min) / focus. The higher the focus, the more probable it is that generated numbers are close to r_max.
void fcl::RNG::quaternion | ( | double | value[4] | ) |
Uniform random unit quaternion sampling. The computed value has the order (x,y,z,w)
Referenced by fcl::SamplerSE3Euler::sample(), fcl::SamplerSE3Quat::sample(), fcl::SamplerSE3Euler_ball::sample(), and fcl::SamplerSE3Quat_ball::sample().
|
static |
Set the seed for random number generation. Use this function to ensure the same sequence of random numbers is generated.
|
inline |
Generate a random real between 0 and 1.
|
inline |
Generate a random boolean.
|
inline |
Generate a random integer within given bounds: [lower_bound, upper_bound].
References uniformReal().
Referenced by fcl::GreedyKCenters< _T >::kcenters().
|
inline |
Generate a random real within given bounds: [lower_bound, upper_bound)
Referenced by fcl::SamplerR< N >::sample(), fcl::SamplerSE2::sample(), fcl::SamplerSE2_disk::sample(), fcl::SamplerSE3Euler::sample(), fcl::SamplerSE3Quat::sample(), and uniformInt().