Abstract base class for random number generators.
More...
#include <randapi.hpp>
|
virtual std::string | name () const =0 |
| Get the name of the random number generation algorithm.
|
|
virtual void | rand_bytes (unsigned char *buf, size_t size)=0 |
| Fill a buffer with random bytes.
|
|
virtual bool | rand_bytes_noexcept (unsigned char *buf, size_t size)=0 |
| Fill a buffer with random bytes without throwing exceptions.
|
|
template<typename T > |
void | rand_fill (T &obj) |
| Fill a data object with random bytes.
|
|
template<typename T > |
T | rand_get () |
| Create a data object filled with random bytes.
|
|
template<typename T > |
T | rand_get_positive () |
| Create a data object filled with random bytes, always >= 0 for signed types.
|
|
template<typename T > |
T | randrange (const T end) |
| Return a uniformly distributed random number in the range [0, end)
|
|
template<typename T > |
T | randrange (const T start, const T end) |
| Return a uniformly distributed random number in the range [start, end].
|
|
std::uint32_t | randrange32 (const std::uint32_t end) |
| Return a uniformly distributed random number in the range [0, end)
|
|
std::uint32_t | randrange32 (const std::uint32_t start, const std::uint32_t end) |
| Return a uniformly distributed random number in the range [start, end].
|
|
std::uint8_t | randbyte () |
| Return a random byte.
|
|
bool | randbool () |
| Return a random boolean.
|
|
| RC () noexcept=default |
|
| RC (const RC &)=delete |
|
virtual | ~RC ()=default |
|
RC & | operator= (const RC &)=delete |
|
olong | use_count () const noexcept |
| Delegates call to RCImpl and returns the result.
|
|
|
static constexpr bool | is_thread_safe () |
| Delegates call to RCImpl and returns the result.
|
|
Abstract base class for random number generators.
This class cannot be inherited from directly, use StrongRandomAPI or WeakRandomAPI to implement random number generators.
Definition at line 38 of file randapi.hpp.
◆ Ptr
Smart pointer type for managing the ownership of RandomAPI objects.
Definition at line 45 of file randapi.hpp.
◆ result_type
◆ RandomAPI()
openvpn::RandomAPI::RandomAPI |
( |
| ) |
|
|
privatedefault |
◆ max()
static constexpr result_type openvpn::RandomAPI::max |
( |
| ) |
|
|
inlinestaticconstexpr |
◆ min()
static constexpr result_type openvpn::RandomAPI::min |
( |
| ) |
|
|
inlinestaticconstexpr |
◆ name()
virtual std::string openvpn::RandomAPI::name |
( |
| ) |
const |
|
pure virtual |
◆ operator()()
◆ rand_bytes()
virtual void openvpn::RandomAPI::rand_bytes |
( |
unsigned char * |
buf, |
|
|
size_t |
size |
|
) |
| |
|
pure virtual |
◆ rand_bytes_noexcept()
virtual bool openvpn::RandomAPI::rand_bytes_noexcept |
( |
unsigned char * |
buf, |
|
|
size_t |
size |
|
) |
| |
|
pure virtual |
◆ rand_fill()
template<typename T >
void openvpn::RandomAPI::rand_fill |
( |
T & |
obj | ) |
|
|
inline |
Fill a data object with random bytes.
- Template Parameters
-
- Parameters
-
obj | Reference to the object to be filled |
Definition at line 75 of file randapi.hpp.
◆ rand_get()
template<typename T >
T openvpn::RandomAPI::rand_get |
( |
| ) |
|
|
inline |
Create a data object filled with random bytes.
- Template Parameters
-
- Returns
- The generated object
Definition at line 86 of file randapi.hpp.
◆ rand_get_positive()
template<typename T >
T openvpn::RandomAPI::rand_get_positive |
( |
| ) |
|
|
inline |
Create a data object filled with random bytes, always >= 0 for signed types.
- Template Parameters
-
- Returns
- The generated data object
Definition at line 99 of file randapi.hpp.
◆ randbool()
bool openvpn::RandomAPI::randbool |
( |
| ) |
|
|
inline |
Return a random boolean.
- Returns
- The generated random boolean
Definition at line 186 of file randapi.hpp.
◆ randbyte()
std::uint8_t openvpn::RandomAPI::randbyte |
( |
| ) |
|
|
inline |
Return a random byte.
- Returns
- The generated random byte
Definition at line 175 of file randapi.hpp.
◆ randrange() [1/2]
template<typename T >
T openvpn::RandomAPI::randrange |
( |
const T |
end | ) |
|
|
inline |
Return a uniformly distributed random number in the range [0, end)
- Template Parameters
-
- Parameters
-
end | The upper bound (exclusive) |
- Returns
- The generated random number
Definition at line 117 of file randapi.hpp.
◆ randrange() [2/2]
template<typename T >
T openvpn::RandomAPI::randrange |
( |
const T |
start, |
|
|
const T |
end |
|
) |
| |
|
inline |
Return a uniformly distributed random number in the range [start, end].
- Template Parameters
-
- Parameters
-
start | The lower bound |
end | The upper bound |
- Returns
- The generated random number
Definition at line 130 of file randapi.hpp.
◆ randrange32() [1/2]
std::uint32_t openvpn::RandomAPI::randrange32 |
( |
const std::uint32_t |
end | ) |
|
|
inline |
Return a uniformly distributed random number in the range [0, end)
- Parameters
-
end | The upper bound (exclusive) |
- Returns
- The generated random number
If end==0 or end==1, will always return 0. This version is strictly 32-bit only and optimizes by avoiding integer division.
Definition at line 147 of file randapi.hpp.
◆ randrange32() [2/2]
std::uint32_t openvpn::RandomAPI::randrange32 |
( |
const std::uint32_t |
start, |
|
|
const std::uint32_t |
end |
|
) |
| |
|
inline |
Return a uniformly distributed random number in the range [start, end].
- Parameters
-
start | The lower bound |
end | The upper bound |
- Returns
- The generated random number
This version is strictly 32-bit only and optimizes by avoiding integer division.
Definition at line 163 of file randapi.hpp.
◆ StrongRandomAPI
◆ WeakRandomAPI
The documentation for this class was generated from the following file: