FCL
0.6.0
Flexible Collision Library
|
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 | |
RNG () | |
Constructor. Always sets a different random seed. | |
S | uniform01 () |
Generate a random real between 0 and 1. | |
S | uniformReal (S lower_bound, S upper_bound) |
Generate a random real within given bounds: [lower_bound, upper_bound) | |
int | uniformInt (int lower_bound, int upper_bound) |
Generate a random integer within given bounds: [lower_bound, upper_bound]. | |
bool | uniformBool () |
Generate a random boolean. | |
S | gaussian01 () |
Generate a random real using a normal distribution with mean 0 and variance 1. | |
S | gaussian (S mean, S stddev) |
Generate a random real using a normal distribution with given mean and variance. | |
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, 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. | |
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() | |
void | quaternion (S value[4]) |
Uniform random unit quaternion sampling. The computed value has the order (x,y,z,w) | |
*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) | |
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. | |
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 Public Member Functions | |
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. | |
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. | |
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.