Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
fcl::RNG< S > Class Template Reference

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

#include <rng.h>

Public Member Functions

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. More...
 
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. More...
 
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) *‍/. More...
 
gaussian (S mean, S stddev)
 Generate a random real using a normal distribution with given mean and variance. More...
 
gaussian01 ()
 Generate a random real using a normal distribution with mean 0 and variance 1. More...
 
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_min, r_max]), but with a bias towards r_max. The function is implemented on top of halfNormalReal() More...
 
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, 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...
 
void quaternion (S value[4])
 Uniform random unit quaternion sampling. The computed value has the order (x,y,z,w) More...
 
 RNG ()
 Constructor. Always sets a different random seed. More...
 
uniform01 ()
 Generate a random real between 0 and 1. More...
 
bool uniformBool ()
 Generate a random boolean. More...
 
int uniformInt (int lower_bound, int upper_bound)
 Generate a random integer within given bounds: [lower_bound, upper_bound]. More...
 
uniformReal (S lower_bound, S upper_bound)
 Generate a random real within given bounds: [lower_bound, upper_bound) More...
 

Static Public Member Functions

static std::uint_fast32_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...
 
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 numbers is generated. More...
 

Private Attributes

std::mt19937 generator_
 
std::normal_distribution normalDist_
 
std::uniform_real_distribution uniDist_
 

Detailed Description

template<typename S>
class fcl::RNG< S >

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.

Definition at line 58 of file rng.h.

Constructor & Destructor Documentation

◆ RNG()

template<typename S >
fcl::RNG< S >::RNG

Constructor. Always sets a different random seed.

Definition at line 52 of file rng-inl.h.

Member Function Documentation

◆ ball()

template<typename S >
void fcl::RNG< S >::ball ( r_min,
r_max,
S &  x,
S &  y,
S &  z 
)

Uniform random sample in a ball with radius from r_min to r_max.

Definition at line 171 of file rng-inl.h.

◆ disk()

template<typename S >
void fcl::RNG< S >::disk ( r_min,
r_max,
S &  x,
S &  y 
)

Uniform random sample on a disk with radius from r_min to r_max.

Definition at line 159 of file rng-inl.h.

◆ eulerRPY()

template<typename S >
void fcl::RNG< S >::eulerRPY ( 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) *‍/.

Definition at line 150 of file rng-inl.h.

◆ gaussian()

template<typename S >
S fcl::RNG< S >::gaussian ( mean,
stddev 
)

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

Definition at line 98 of file rng-inl.h.

◆ gaussian01()

template<typename S >
S fcl::RNG< S >::gaussian01

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

Definition at line 91 of file rng-inl.h.

◆ getSeed()

template<typename S >
uint_fast32_t fcl::RNG< S >::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.

Definition at line 213 of file rng-inl.h.

◆ halfNormalInt()

template<typename S >
int fcl::RNG< S >::halfNormalInt ( int  r_min,
int  r_max,
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()

Definition at line 122 of file rng-inl.h.

◆ halfNormalReal()

template<typename S >
S fcl::RNG< S >::halfNormalReal ( r_min,
r_max,
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.

Definition at line 105 of file rng-inl.h.

◆ quaternion()

template<typename S >
void fcl::RNG< S >::quaternion ( value[4])

Uniform random unit quaternion sampling. The computed value has the order (x,y,z,w)

Definition at line 132 of file rng-inl.h.

◆ setSeed()

template<typename S >
void fcl::RNG< S >::setSeed ( std::uint_fast32_t  seed)
static

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

Definition at line 192 of file rng-inl.h.

◆ uniform01()

template<typename S >
S fcl::RNG< S >::uniform01

Generate a random real between 0 and 1.

Definition at line 59 of file rng-inl.h.

◆ uniformBool()

template<typename S >
bool fcl::RNG< S >::uniformBool

Generate a random boolean.

Definition at line 84 of file rng-inl.h.

◆ uniformInt()

template<typename S >
int fcl::RNG< S >::uniformInt ( int  lower_bound,
int  upper_bound 
)

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

Definition at line 75 of file rng-inl.h.

◆ uniformReal()

template<typename S >
S fcl::RNG< S >::uniformReal ( lower_bound,
upper_bound 
)

Generate a random real within given bounds: [lower_bound, upper_bound)

Definition at line 66 of file rng-inl.h.

Member Data Documentation

◆ generator_

template<typename S >
std::mt19937 fcl::RNG< S >::generator_
private

Definition at line 125 of file rng.h.

◆ normalDist_

template<typename S >
std::normal_distribution fcl::RNG< S >::normalDist_
private

Definition at line 127 of file rng.h.

◆ uniDist_

template<typename S >
std::uniform_real_distribution fcl::RNG< S >::uniDist_
private

Definition at line 126 of file rng.h.


The documentation for this class was generated from the following files:


fcl
Author(s):
autogenerated on Tue Dec 5 2023 03:40:50