Class RandomNumberGenerator
Defined in File random.hpp
Inheritance Relationships
Derived Types
public navtk::experimental::LocalEngineWrapper(Class LocalEngineWrapper)public navtk::experimental::RandomNumberEngineWrapper< TEngine >(Template Class RandomNumberEngineWrapper)
Class Documentation
Abstraction layer for random number generation.
Subclasses of this type must define a seed setter and a function returning random double-precision numbers uniformly distributed between 0 and 1. Implementations should strive for consistent high performance over cryptographic unpredictability. Avoid depending on finite pools of entropy (such as
/dev/random) as these will be quickly exhausted and cause filtering performance issues.Namespace-level random functions, including s_rand(), navtk::experimental::rand() and navtk::experimental::rand_n(), are all implemented by calling methods on the current value of get_global_rng().
If you have an existing random number generator that conforms to the C++ RandomNumberEngine named requirements, you can use the RandomNumberEngineWrapper template class to convert it to RandomNumberGenerator.
Subclassed by navtk::experimental::LocalEngineWrapper, navtk::experimental::RandomNumberEngineWrapper< TEngine >
Public Functions
Copy and move are deleted to prevent object slicing.
Use
std::shared_ptr.
Copy and move are deleted to prevent object slicing.
Use
std::shared_ptr.
Copy and move are deleted to prevent object slicing.
Use
std::shared_ptr.
Copy and move are deleted to prevent object slicing.
Use
std::shared_ptr.
Reset the state of the underlying random number generation algorithm.
- Parameters
seed – New seed value.
- Returns
A single random number from a uniform distribution between 0 and 1.
- Parameters
num – Size of desired output Vector.
- Returns
A Vector of the requested size populated with samples from a uniform distribution between 0 and 1, using calls to this->rand() to generate those values.
- Parameters
num_rows – Row count of the output Matrix.
num_cols – Column count of the output Matrix.
- Returns
A Matrix of the requested shape populated with samples from a uniform distribution between 0 and 1, using calls to this->rand() to generate those values.
Return a single random number from a normal (Gaussian) distribution with mean=0, sigma=1.
The default implementation uses this->rand() as a source of uniform randomness and transforms this to gaussian using the Marsaglia Polar Method. Subclasses may override this function if a different sampling algorithm is desired.
- Returns
A single random number from a normal (Gaussian) distribution with mean=0, sigma=1.
- Parameters
num – Size of the output Vector
- Returns
A Vector of the requested size populated with samples from a normal (Gaussian) distribution with mean=0, sigma=1, using calls to this->rand_n() to generate those values.
- Parameters
num_rows – Row count of the output Matrix.
num_cols – Column count of the output Matrix.
- Returns
A Matrix of the requested shape populated with samples from a normal (Gaussian) distribution with mean=0, sigma=1, using calls to this->rand_n() to generate those values.