![]() |
Bitcoin Core 30.99.0
P2P Digital Currency
|
Fast randomness source. More...
#include <random.h>
Public Member Functions | |
| FastRandomContext (bool fDeterministic=false) noexcept | |
| Construct a FastRandomContext with GetRandHash()-based entropy (or zero key if fDeterministic). More... | |
| FastRandomContext (const uint256 &seed) noexcept | |
| Initialize with explicit seed (only for testing) More... | |
| void | Reseed (const uint256 &seed) noexcept |
| Reseed with explicit seed (only for testing). More... | |
| uint64_t | rand64 () noexcept |
| Generate a random 64-bit integer. More... | |
| void | fillrand (std::span< std::byte > output) noexcept |
| Fill a byte span with random bytes. More... | |
Public Member Functions inherited from RandomMixin< FastRandomContext > | |
| constexpr | RandomMixin () noexcept=default |
| RandomMixin (const RandomMixin &)=delete | |
| RandomMixin (RandomMixin &&)=delete | |
| RandomMixin & | operator= (const RandomMixin &)=delete |
| RandomMixin & | operator= (RandomMixin &&)=delete |
| uint64_t | randbits (int bits) noexcept |
| Generate a random (bits)-bit integer. More... | |
| uint64_t | randbits () noexcept |
| Same as above, but with compile-time fixed bits count. More... | |
| I | randrange (I range) noexcept |
| Generate a random integer in the range [0..range), with range > 0. More... | |
| Dur | randrange (std::common_type_t< Dur > range) noexcept |
| Generate a uniform random duration in the range [0..max). More... | |
| void | fillrand (std::span< std::byte > span) noexcept |
| Fill a span with random bytes. More... | |
| I | rand () noexcept |
| Generate a random integer in its entire (non-negative) range. More... | |
| std::vector< B > | randbytes (size_t len) noexcept |
| Generate random bytes. More... | |
| 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... | |
| Tp | rand_uniform_delay (const Tp &time, typename Tp::duration range) noexcept |
| Return the time point advanced by a uniform random duration. More... | |
| 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... | |
| 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 |
Private Member Functions | |
| void | RandomSeed () noexcept |
Private Attributes | |
| bool | requires_seed |
| ChaCha20 | rng |
Additional Inherited Members | |
Public Types inherited from RandomMixin< FastRandomContext > | |
| typedef uint64_t | result_type |
Static Public Member Functions inherited from RandomMixin< FastRandomContext > | |
| static constexpr uint64_t | min () noexcept |
| static constexpr uint64_t | max () noexcept |
Protected Member Functions inherited from RandomMixin< FastRandomContext > | |
| constexpr void | FlushCache () noexcept |
Fast randomness source.
This is seeded once with secure random data, but is completely deterministic and does not gather more entropy after that.
This class is not thread-safe.
|
explicitnoexcept |
Construct a FastRandomContext with GetRandHash()-based entropy (or zero key if fDeterministic).
Definition at line 689 of file random.cpp.
|
explicitnoexcept |
Initialize with explicit seed (only for testing)
Definition at line 632 of file random.cpp.
|
noexcept |
Fill a byte span with random bytes.
This overrides the RandomMixin version.
Definition at line 626 of file random.cpp.
|
inlinenoexcept |
|
privatenoexcept |
Definition at line 619 of file random.cpp.
|
noexcept |
Reseed with explicit seed (only for testing).
Definition at line 634 of file random.cpp.