All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
fcl::RNG Class Reference

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...
 

Detailed Description

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.

Constructor & Destructor Documentation

fcl::RNG::RNG ( )

Constructor. Always sets a different random seed.

Member Function Documentation

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) */.

double fcl::RNG::gaussian ( double  mean,
double  stddev 
)
inline

Generate a random real using a normal distribution with given mean and variance.

double fcl::RNG::gaussian01 ( )
inline

Generate a random real using a normal distribution with mean 0 and variance 1.

static boost::uint32_t fcl::RNG::getSeed ( )
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 void fcl::RNG::setSeed ( boost::uint32_t  seed)
static

Set the seed for random number generation. Use this function to ensure the same sequence of random numbers is generated.

double fcl::RNG::uniform01 ( )
inline

Generate a random real between 0 and 1.

bool fcl::RNG::uniformBool ( )
inline

Generate a random boolean.

int fcl::RNG::uniformInt ( int  lower_bound,
int  upper_bound 
)
inline

Generate a random integer within given bounds: [lower_bound, upper_bound].

References uniformReal().

Referenced by fcl::GreedyKCenters< _T >::kcenters().

double fcl::RNG::uniformReal ( double  lower_bound,
double  upper_bound 
)
inline