]>
Commit | Line | Data |
---|---|---|
6354935c PK |
1 | // Copyright (c) 2009-2010 Satoshi Nakamoto |
2 | // Copyright (c) 2009-2014 The Bitcoin developers | |
78253fcb | 3 | // Distributed under the MIT software license, see the accompanying |
6354935c PK |
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 | */ | |
65e3a1e7 | 22 | void GetRandBytes(unsigned char* buf, int num); |
6354935c PK |
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. | |
3a05ba1b | 29 | * @param Deterministic Use a deterministic seed |
6354935c PK |
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 |