mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 14:38:29 +01:00
Make FastRandomContext support standard C++11 RNG interface
This makes it possible to plug it into the various standard C++11 random distribution algorithms and other functions like std::shuffle.
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include <uint256.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <limits>
|
||||
|
||||
/* Seed OpenSSL PRNG with additional entropy data */
|
||||
void RandAddSeed();
|
||||
@@ -121,6 +122,12 @@ public:
|
||||
|
||||
/** Generate a random boolean. */
|
||||
bool randbool() { return randbits(1); }
|
||||
|
||||
// Compatibility with the C++11 UniformRandomBitGenerator concept
|
||||
typedef uint64_t result_type;
|
||||
static constexpr uint64_t min() { return 0; }
|
||||
static constexpr uint64_t max() { return std::numeric_limits<uint64_t>::max(); }
|
||||
inline uint64_t operator()() { return rand64(); }
|
||||
};
|
||||
|
||||
/* Number of random bytes returned by GetOSRand.
|
||||
|
||||
Reference in New Issue
Block a user