aboutsummaryrefslogtreecommitdiff
path: root/src/random.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/random.h')
-rw-r--r--src/random.h35
1 files changed, 16 insertions, 19 deletions
diff --git a/src/random.h b/src/random.h
index 31b80bd565..e97d2d1fb0 100644
--- a/src/random.h
+++ b/src/random.h
@@ -28,25 +28,22 @@ uint256 GetRandHash();
void GetStrongRandBytes(unsigned char* buf, int num);
/**
- * Seed insecure_rand using the random pool.
- * @param Deterministic Use a deterministic seed
+ * Fast randomness source. This is seeded once with secure random data, but
+ * is completely deterministic and insecure after that.
+ * This class is not thread-safe.
*/
-void seed_insecure_rand(bool fDeterministic = false);
-
-/**
- * MWC RNG of George Marsaglia
- * This is intended to be fast. It has a period of 2^59.3, though the
- * least significant 16 bits only have a period of about 2^30.1.
- *
- * @return random value
- */
-extern uint32_t insecure_rand_Rz;
-extern uint32_t insecure_rand_Rw;
-static inline uint32_t insecure_rand(void)
-{
- insecure_rand_Rz = 36969 * (insecure_rand_Rz & 65535) + (insecure_rand_Rz >> 16);
- insecure_rand_Rw = 18000 * (insecure_rand_Rw & 65535) + (insecure_rand_Rw >> 16);
- return (insecure_rand_Rw << 16) + insecure_rand_Rz;
-}
+class FastRandomContext {
+public:
+ explicit FastRandomContext(bool fDeterministic=false);
+
+ uint32_t rand32() {
+ Rz = 36969 * (Rz & 65535) + (Rz >> 16);
+ Rw = 18000 * (Rw & 65535) + (Rw >> 16);
+ return (Rw << 16) + Rz;
+ }
+
+ uint32_t Rz;
+ uint32_t Rw;
+};
#endif // BITCOIN_RANDOM_H