diff options
| author | MarcoFalke <[email protected]> | 2018-03-22 12:21:41 -0400 |
|---|---|---|
| committer | MarcoFalke <[email protected]> | 2018-03-22 12:21:46 -0400 |
| commit | f686002a8eba820a40ac2f34a6e8f57b2b5cc54c (patch) | |
| tree | af61b257c03dc5f00c5ae640a51f7b2e364027f5 /src/random.h | |
| parent | Merge #12630: Provide useful error message if datadir is not writable. (diff) | |
| parent | Make FastRandomContext support standard C++11 RNG interface (diff) | |
| download | discoin-f686002a8eba820a40ac2f34a6e8f57b2b5cc54c.tar.xz discoin-f686002a8eba820a40ac2f34a6e8f57b2b5cc54c.zip | |
Merge #12742: Make FastRandomContext support standard C++11 RNG interface
1ec1602a45 Make FastRandomContext support standard C++11 RNG interface (Pieter Wuille)
Pull request description:
This makes it possible to plug it into the various standard C++11 random distribution algorithms and other functions like `std::shuffle`.
Tree-SHA512: 935eae9c4fae31e1964c16d9cf9d0fcfa899e04567f010d8b3e1ff824e55e2392aa838ba743d03c1b2a5010c5b8da04343f453983dfeed83747d85828a564713
Diffstat (limited to 'src/random.h')
| -rw-r--r-- | src/random.h | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/random.h b/src/random.h index 5fe8f2fd0..1d6b13a53 100644 --- a/src/random.h +++ b/src/random.h @@ -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. |