51 virtual std::string
name()
const = 0;
58 virtual void rand_bytes(
unsigned char *buf,
size_t size) = 0;
77 rand_bytes(
reinterpret_cast<unsigned char *
>(&obj),
sizeof(T));
101 T
ret = rand_get<T>();
102 if constexpr (std::is_signed_v<T>)
105 ret &= std::numeric_limits<T>::max();
116 template <
typename T>
119 return rand_get_positive<T>() % end;
129 template <
typename T>
135 return start + rand_get_positive<T>() % (end - start + 1);
163 std::uint32_t
randrange32(
const std::uint32_t start,
const std::uint32_t end)
210 return rand_get<result_type>();
Reference count base class for objects tracked by RCPtr. Disallows copying and assignment.
Abstract base class for random number generators.
RCPtr< RandomAPI > Ptr
Smart pointer type for managing the ownership of RandomAPI objects.
T rand_get()
Create a data object filled with random bytes.
virtual std::string name() const =0
Get the name of the random number generation algorithm.
T randrange(const T start, const T end)
Return a uniformly distributed random number in the range [start, end].
virtual bool rand_bytes_noexcept(unsigned char *buf, size_t size)=0
Fill a buffer with random bytes without throwing exceptions.
std::uint8_t randbyte()
Return a random byte.
void rand_fill(T &obj)
Fill a data object with random bytes.
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].
static constexpr result_type max()
std::uint32_t randrange32(const std::uint32_t end)
Return a uniformly distributed random number in the range [0, end)
T rand_get_positive()
Create a data object filled with random bytes, always >= 0 for signed types.
static constexpr result_type min()
virtual void rand_bytes(unsigned char *buf, size_t size)=0
Fill a buffer with random bytes.
bool randbool()
Return a random boolean.
T randrange(const T end)
Return a uniformly distributed random number in the range [0, end)
Abstract base class for cryptographically strong random number generators.
RCPtr< StrongRandomAPI > Ptr
Smart pointer type for managing the ownership of StrongRandomAPI objects.
Abstract base class for pseudo random number generators.
RCPtr< WeakRandomAPI > Ptr
Smart pointer type for managing the ownership of WeakRandomAPI objects.
Support deferred server-side state creation when client connects.
std::uint32_t rand32_distribute(const std::uint32_t seed, const std::uint32_t end)