rsl  1.1.0
ROS Support Library
random.hpp File Reference
#include <rsl/export.hpp>
#include <Eigen/Geometry>
#include <cassert>
#include <random>
#include <type_traits>

Go to the source code of this file.

Functions

RSL_EXPORT auto rsl::rng (std::seed_seq seed_sequence={}) -> std::mt19937 &
 Get a random number generator. More...
 
template<typename RealType >
auto rsl::uniform_real (RealType lower, RealType upper)
 Get a uniform real number in a given range. More...
 
template<typename IntType >
auto rsl::uniform_int (IntType lower, IntType upper)
 Get a uniform integer number in a given range. More...
 
RSL_EXPORT auto rsl::random_unit_quaternion () -> Eigen::Quaterniond
 Generate a random unit quaternion of doubles. More...
 

Function Documentation

◆ random_unit_quaternion()

RSL_EXPORT auto rsl::random_unit_quaternion ( ) -> Eigen::Quaterniond

Generate a random unit quaternion of doubles.

Returns
Random unit quaternion

◆ rng()

RSL_EXPORT auto rsl::rng ( std::seed_seq  seed_sequence = {}) -> std::mt19937 &

Get a random number generator.

The first time this function is called it creates a thread_local random number generator. If a seed sequence is provided on that first call it is used to create the generator, otherwise the random device is used to seed the generator. After the first call to this function, if a seed sequence is provided this function throws. The returned value is a reference to a thread_local static generator.

Parameters
seed_sequenceSeed sequence for random number generator
Returns
Seeded random number generator

◆ uniform_int()

template<typename IntType >
auto rsl::uniform_int ( IntType  lower,
IntType  upper 
)

Get a uniform integer number in a given range.

Parameters
lowerLower bound, inclusive
upperUpper bound, inclusive
Template Parameters
IntTypeIntegral type
Returns
Uniform integer in range [lower, upper]

◆ uniform_real()

template<typename RealType >
auto rsl::uniform_real ( RealType  lower,
RealType  upper 
)

Get a uniform real number in a given range.

Parameters
lowerLower bound, inclusive
upperUpper bound, exclusive
Template Parameters
RealTypeFloating point type
Returns
Uniform real in range [lower, upper)