Introduce enum ServiceFlags for service flags
[bitcoinplatinum.git] / src / random.h
blob31b80bd565bdc2ce0b11d3ee648b49a56b6fa5b9
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2014 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 #ifndef BITCOIN_RANDOM_H
7 #define BITCOIN_RANDOM_H
9 #include "uint256.h"
11 #include <stdint.h>
13 /* Seed OpenSSL PRNG with additional entropy data */
14 void RandAddSeed();
16 /**
17 * Functions to gather random data via the OpenSSL PRNG
19 void GetRandBytes(unsigned char* buf, int num);
20 uint64_t GetRand(uint64_t nMax);
21 int GetRandInt(int nMax);
22 uint256 GetRandHash();
24 /**
25 * Function to gather random data from multiple sources, failing whenever any
26 * of those source fail to provide a result.
28 void GetStrongRandBytes(unsigned char* buf, int num);
30 /**
31 * Seed insecure_rand using the random pool.
32 * @param Deterministic Use a deterministic seed
34 void seed_insecure_rand(bool fDeterministic = false);
36 /**
37 * MWC RNG of George Marsaglia
38 * This is intended to be fast. It has a period of 2^59.3, though the
39 * least significant 16 bits only have a period of about 2^30.1.
41 * @return random value
43 extern uint32_t insecure_rand_Rz;
44 extern uint32_t insecure_rand_Rw;
45 static inline uint32_t insecure_rand(void)
47 insecure_rand_Rz = 36969 * (insecure_rand_Rz & 65535) + (insecure_rand_Rz >> 16);
48 insecure_rand_Rw = 18000 * (insecure_rand_Rw & 65535) + (insecure_rand_Rw >> 16);
49 return (insecure_rand_Rw << 16) + insecure_rand_Rz;
52 #endif // BITCOIN_RANDOM_H