Bitcoin Core  29.1.0
P2P Digital Currency
random.h
Go to the documentation of this file.
1 // Copyright (c) 2023-present The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef BITCOIN_TEST_UTIL_RANDOM_H
6 #define BITCOIN_TEST_UTIL_RANDOM_H
7 
8 #include <consensus/amount.h>
9 #include <random.h>
10 #include <uint256.h>
11 
12 #include <atomic>
13 #include <cstdint>
14 
15 enum class SeedRand {
19  ZEROS,
25  FIXED_SEED,
26 };
27 
30 
31 extern std::atomic<bool> g_seeded_g_prng_zero;
32 extern std::atomic<bool> g_used_g_prng;
33 
34 template <RandomNumberGenerator Rng>
35 inline CAmount RandMoney(Rng&& rng)
36 {
37  return CAmount{rng.randrange(MAX_MONEY + 1)};
38 }
39 
40 #endif // BITCOIN_TEST_UTIL_RANDOM_H
Seed with a fixed value that never changes over the lifetime of this process.
void SeedRandomStateForTest(SeedRand seed)
Seed the global RNG state for testing and log the seed value.
Definition: random.cpp:19
std::atomic< bool > g_seeded_g_prng_zero
Definition: random.cpp:15
SeedRand
Definition: random.h:15
std::atomic< bool > g_used_g_prng
Definition: random.cpp:601
CAmount RandMoney(Rng &&rng)
Definition: random.h:35
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
static constexpr CAmount MAX_MONEY
No amount larger than this (in satoshi) is valid.
Definition: amount.h:26
Seed with a compile time constant of zeros.