Mixin class that provides helper randomness functions.
More...
#include <random.h>
|
| static constexpr uint64_t | min () noexcept |
| static constexpr uint64_t | max () noexcept |
template<typename
T>
class RandomMixin< T >
Mixin class that provides helper randomness functions.
Intended to be used through CRTP: https://en.cppreference.com/w/cpp/language/crtp. An RNG class FunkyRNG would derive publicly from RandomMixin<FunkyRNG>. This permits RandomMixin from accessing the derived class's rand64() function, while also allowing the derived class to provide more.
The derived class must satisfy the RandomNumberGenerator concept.
Definition at line 174 of file random.h.
◆ result_type
◆ RandomMixin() [1/3]
◆ RandomMixin() [2/3]
◆ RandomMixin() [3/3]
◆ fillrand()
| void RandomMixin< T >::fillrand |
( |
std::span< std::byte > | span | ) |
|
|
inlinenoexcept |
Fill a span with random bytes.
Definition at line 267 of file random.h.
◆ FlushCache()
|
|
inlineconstexprprotectednoexcept |
◆ Impl()
Access the underlying generator.
This also enforces the RandomNumberGenerator concept. We cannot declare that in the template (no template<RandomNumberGenerator T>) because the type isn't fully instantiated yet there.
Definition at line 185 of file random.h.
◆ max()
|
|
inlinestaticconstexprnoexcept |
◆ min()
|
|
inlinestaticconstexprnoexcept |
◆ operator()()
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ rand()
template<std::integral I>
Generate a random integer in its entire (non-negative) range.
Definition at line 287 of file random.h.
◆ rand256()
◆ rand32()
Generate a random 32-bit integer.
Definition at line 314 of file random.h.
◆ rand_exp_duration()
| std::chrono::microseconds RandomMixin< T >::rand_exp_duration |
( |
std::chrono::microseconds | mean | ) |
|
|
inlinenoexcept |
Return a duration sampled from an exponential distribution (https://en.wikipedia.org/wiki/Exponential_distribution).
Successive events whose intervals are distributed according to this form a memoryless Poisson process. This should be used for repeated network events (e.g. sending a certain type of message) to minimize leaking information to observers.
The probability of an event occurring before time x is 1 - e^-(x/a) where a is the average interval between events.
Definition at line 365 of file random.h.
◆ rand_uniform_delay()
template<typename Tp>
| Tp RandomMixin< T >::rand_uniform_delay |
( |
const Tp & | time, |
|
|
typename Tp::duration | range ) |
|
inlinenoexcept |
Return the time point advanced by a uniform random duration.
Definition at line 329 of file random.h.
◆ rand_uniform_duration()
template<typename Chrono>
| Chrono::duration RandomMixin< T >::rand_uniform_duration |
( |
typename Chrono::duration | range | ) |
|
|
inlinenoexcept |
Generate a uniform random duration in the range from 0 (inclusive) to range (exclusive).
Definition at line 336 of file random.h.
◆ randbits() [1/2]
Same as above, but with compile-time fixed bits count.
Definition at line 230 of file random.h.
◆ randbits() [2/2]
Generate a random (bits)-bit integer.
Definition at line 204 of file random.h.
◆ randbool()
Generate a random boolean.
Definition at line 325 of file random.h.
◆ randbytes() [1/2]
Generate fixed-size random bytes.
Definition at line 306 of file random.h.
◆ randbytes() [2/2]
Generate random bytes.
Definition at line 297 of file random.h.
◆ randrange() [1/2]
template<std::integral I>
Generate a random integer in the range [0..range), with range > 0.
Definition at line 254 of file random.h.
◆ randrange() [2/2]
| Dur RandomMixin< T >::randrange |
( |
std::common_type_t< Dur > | range | ) |
|
|
inlinenoexcept |
Generate a uniform random duration in the range [0..max).
Precondition: max.count() > 0
Definition at line 346 of file random.h.
◆ bitbuf
◆ bitbuf_size
The documentation for this class was generated from the following file: