rsl 1.1.0
ROS Support Library
Loading...
Searching...
No Matches
random.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <rsl/export.hpp>
4
5#include <Eigen/Geometry>
6#include <cassert>
7#include <random>
8#include <type_traits>
9
10namespace rsl {
11
27RSL_EXPORT auto rng(std::seed_seq seed_sequence = {}) -> std::mt19937&;
28
39template <typename RealType>
40[[nodiscard]] auto uniform_real(RealType lower, RealType upper) {
41 static_assert(std::is_floating_point_v<RealType>, "RealType must be a floating point type");
42 assert(lower < upper && "rsl::uniform_real: Lower bound be less than upper bound");
43 return std::uniform_real_distribution(lower, upper)(rng());
44}
45
56template <typename IntType>
57[[nodiscard]] auto uniform_int(IntType lower, IntType upper) {
58 static_assert(std::is_integral_v<IntType>, "IntType must be an integral type");
59 assert(lower <= upper &&
60 "rsl::uniform_int: Lower bound must be less than or equal to upper bound");
61 return std::uniform_int_distribution(lower, upper)(rng());
62}
63
68[[nodiscard]] RSL_EXPORT auto random_unit_quaternion() -> Eigen::Quaterniond;
69
70} // namespace rsl
RSL_EXPORT auto rng(std::seed_seq seed_sequence={}) -> std::mt19937 &
Get a random number generator.
auto uniform_real(RealType lower, RealType upper)
Get a uniform real number in a given range.
Definition random.hpp:40
RSL_EXPORT auto random_unit_quaternion() -> Eigen::Quaterniond
Generate a random unit quaternion of doubles.
auto uniform_int(IntType lower, IntType upper)
Get a uniform integer number in a given range.
Definition random.hpp:57