aboutsummaryrefslogtreecommitdiff
path: root/src/random.h
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2018-03-20 19:10:39 -0700
committerPieter Wuille <pieter.wuille@gmail.com>2018-03-20 21:24:49 -0700
commit1ec1602a4549f6b68586cead8eff701bceb624f5 (patch)
tree39620ad95f180c7e3cb24ada85e8fbb70defa921 /src/random.h
parent4ba3d4f4393d81148422d24d222fe7ed00130194 (diff)
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.
Diffstat (limited to 'src/random.h')
-rw-r--r--src/random.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/random.h b/src/random.h
index ea88670a37..632ab05883 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.