![]() |
Bitcoin Core 30.99.0
P2P Digital Currency
|
Mixin class that provides helper randomness functions. More...
#include <random.h>
Public Types | |
| typedef uint64_t | result_type |
Public Member Functions | |
| constexpr | RandomMixin () noexcept=default |
| RandomMixin (const RandomMixin &)=delete | |
| RandomMixin & | operator= (const RandomMixin &)=delete |
| RandomMixin (RandomMixin &&)=delete | |
| RandomMixin & | operator= (RandomMixin &&)=delete |
| uint64_t | randbits (int bits) noexcept |
| Generate a random (bits)-bit integer. More... | |
| template<int Bits> | |
| uint64_t | randbits () noexcept |
| Same as above, but with compile-time fixed bits count. More... | |
| template<std::integral I> | |
| I | randrange (I range) noexcept |
| Generate a random integer in the range [0..range), with range > 0. More... | |
| void | fillrand (std::span< std::byte > span) noexcept |
| Fill a span with random bytes. More... | |
| template<std::integral I> | |
| I | rand () noexcept |
| Generate a random integer in its entire (non-negative) range. More... | |
| template<BasicByte B = unsigned char> | |
| std::vector< B > | randbytes (size_t len) noexcept |
| Generate random bytes. More... | |
| template<size_t N, BasicByte B = std::byte> | |
| std::array< B, N > | randbytes () noexcept |
| Generate fixed-size random bytes. More... | |
| uint32_t | rand32 () noexcept |
| Generate a random 32-bit integer. More... | |
| uint256 | rand256 () noexcept |
| generate a random uint256. More... | |
| bool | randbool () noexcept |
| Generate a random boolean. More... | |
| template<typename Tp > | |
| Tp | rand_uniform_delay (const Tp &time, typename Tp::duration range) noexcept |
| Return the time point advanced by a uniform random duration. More... | |
| template<typename Chrono > requires StdChronoDuration<typename Chrono::duration> | |
| Chrono::duration | rand_uniform_duration (typename Chrono::duration range) noexcept |
| Generate a uniform random duration in the range from 0 (inclusive) to range (exclusive). More... | |
| template<StdChronoDuration Dur> | |
| Dur | randrange (std::common_type_t< Dur > range) noexcept |
| Generate a uniform random duration in the range [0..max). More... | |
| std::chrono::microseconds | rand_exp_duration (std::chrono::microseconds mean) noexcept |
| Return a duration sampled from an exponential distribution (https://en.wikipedia.org/wiki/Exponential_distribution). More... | |
| uint64_t | operator() () noexcept |
Static Public Member Functions | |
| static constexpr uint64_t | min () noexcept |
| static constexpr uint64_t | max () noexcept |
Protected Member Functions | |
| constexpr void | FlushCache () noexcept |
Private Member Functions | |
| RandomNumberGenerator auto & | Impl () noexcept |
| Access the underlying generator. More... | |
Private Attributes | |
| uint64_t | bitbuf {0} |
| int | bitbuf_size {0} |
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.
| typedef uint64_t RandomMixin< T >::result_type |
|
constexprdefaultnoexcept |
|
delete |
|
delete |
|
inlinenoexcept |
|
inlineconstexprprotectednoexcept |
|
inlineprivatenoexcept |
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.
|
inlinestaticconstexprnoexcept |
|
inlinestaticconstexprnoexcept |
|
inlinenoexcept |
|
delete |
|
delete |
|
inlinenoexcept |
|
inlinenoexcept |
|
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.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
private |
|
private |