aboutsummaryrefslogtreecommitdiff
path: root/src/util.h
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2013-02-22 08:57:38 -0800
committerGavin Andresen <gavinandresen@gmail.com>2013-02-22 08:57:38 -0800
commitaaeb443791f880351692ac020e8fdea44d2270b0 (patch)
treec32831368135385ed93bbe737b2d441e874b6b87 /src/util.h
parent1167af7e5ca7f9bccc383e6ec1feb3edbbefa191 (diff)
parent907a2aa4c78833ce93455567ae10ff2f506e752e (diff)
downloadbitcoin-aaeb443791f880351692ac020e8fdea44d2270b0.tar.xz
Merge pull request #2312 from gmaxwell/random_random
ApproximateBestSubset internal RNG to prevent degenerate behavior.
Diffstat (limited to 'src/util.h')
-rw-r--r--src/util.h26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/util.h b/src/util.h
index 2050604e54..a6b88206e9 100644
--- a/src/util.h
+++ b/src/util.h
@@ -404,13 +404,27 @@ bool SoftSetArg(const std::string& strArg, const std::string& strValue);
*/
bool SoftSetBoolArg(const std::string& strArg, bool fValue);
+/**
+ * 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;
+}
-
-
-
-
-
-
+/**
+ * Seed insecure_rand using the random pool.
+ * @param Deterministic Use a determinstic seed
+ */
+void seed_insecure_rand(bool fDeterministic=false);
/** Median filter over a stream of values.
* Returns the median of the last N numbers