Bitcoin Core 28.99.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
15enum class SeedRand {
19 ZEROS,
26};
27
30
31extern std::atomic<bool> g_seeded_g_prng_zero;
32extern std::atomic<bool> g_used_g_prng;
33
34template <RandomNumberGenerator Rng>
35inline CAmount RandMoney(Rng&& rng)
36{
37 return CAmount{rng.randrange(MAX_MONEY + 1)};
38}
39
40#endif // BITCOIN_TEST_UTIL_RANDOM_H
static constexpr CAmount MAX_MONEY
No amount larger than this (in satoshi) is valid.
Definition: amount.h:26
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
SeedRand
Definition: random.h:15
@ ZEROS
Seed with a compile time constant of zeros.
@ FIXED_SEED
Seed with a fixed value that never changes over the lifetime of this process.
std::atomic< bool > g_used_g_prng
Definition: random.cpp:674
std::atomic< bool > g_seeded_g_prng_zero
Definition: random.cpp:15
CAmount RandMoney(Rng &&rng)
Definition: random.h:35
void SeedRandomStateForTest(SeedRand seed)
Seed the global RNG state for testing and log the seed value.
Definition: random.cpp:19