]> Git Repo - VerusCoin.git/blob - src/random.h
Merge pull request #5237
[VerusCoin.git] / src / random.h
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2014 The Bitcoin developers
3 // Distributed under the MIT/X11 software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6 #ifndef BITCOIN_RANDOM_H
7 #define BITCOIN_RANDOM_H
8
9 #include "uint256.h"
10
11 #include <stdint.h>
12
13 /**
14  * Seed OpenSSL PRNG with additional entropy data
15  */
16 void RandAddSeed();
17 void RandAddSeedPerfmon();
18
19 /**
20  * Functions to gather random data via the OpenSSL PRNG
21  */
22 void GetRandBytes(unsigned char* buf, int num);
23 uint64_t GetRand(uint64_t nMax);
24 int GetRandInt(int nMax);
25 uint256 GetRandHash();
26
27 /**
28  * Seed insecure_rand using the random pool.
29  * @param Deterministic Use a determinstic seed
30  */
31 void seed_insecure_rand(bool fDeterministic = false);
32
33 /**
34  * MWC RNG of George Marsaglia
35  * This is intended to be fast. It has a period of 2^59.3, though the
36  * least significant 16 bits only have a period of about 2^30.1.
37  *
38  * @return random value
39  */
40 extern uint32_t insecure_rand_Rz;
41 extern uint32_t insecure_rand_Rw;
42 static inline uint32_t insecure_rand(void)
43 {
44     insecure_rand_Rz = 36969 * (insecure_rand_Rz & 65535) + (insecure_rand_Rz >> 16);
45     insecure_rand_Rw = 18000 * (insecure_rand_Rw & 65535) + (insecure_rand_Rw >> 16);
46     return (insecure_rand_Rw << 16) + insecure_rand_Rz;
47 }
48
49 #endif // BITCOIN_RANDOM_H
This page took 0.0235 seconds and 4 git commands to generate.