Bitcoin Core  25.99.0
P2P Digital Currency
random.h
Go to the documentation of this file.
1 // Copyright (c) 2023 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 <test/util/setup_common.h>
11 #include <uint256.h>
12 
13 #include <cstdint>
14 
15 static inline uint32_t InsecureRand32()
16 {
17  return g_insecure_rand_ctx.rand32();
18 }
19 
20 static inline uint256 InsecureRand256()
21 {
23 }
24 
25 static inline uint64_t InsecureRandBits(int bits)
26 {
27  return g_insecure_rand_ctx.randbits(bits);
28 }
29 
30 static inline uint64_t InsecureRandRange(uint64_t range)
31 {
32  return g_insecure_rand_ctx.randrange(range);
33 }
34 
35 static inline bool InsecureRandBool()
36 {
38 }
39 
41 {
42  return static_cast<CAmount>(InsecureRandRange(MAX_MONEY + 1));
43 }
44 
45 #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
uint32_t rand32() noexcept
Generate a random 32-bit integer.
Definition: random.h:217
uint256 rand256() noexcept
generate a random uint256.
Definition: random.cpp:584
bool randbool() noexcept
Generate a random boolean.
Definition: random.h:223
uint64_t randbits(int bits) noexcept
Generate a random (bits)-bit integer.
Definition: random.h:184
uint64_t randrange(uint64_t range) noexcept
Generate a random integer in the range [0..range).
Definition: random.h:202
256-bit opaque blob.
Definition: uint256.h:105
FastRandomContext g_insecure_rand_ctx
This global and the helpers that use it are not thread-safe.
static CAmount InsecureRandMoneyAmount()
Definition: random.h:40
static uint64_t InsecureRandRange(uint64_t range)
Definition: random.h:30
static uint256 InsecureRand256()
Definition: random.h:20
static uint64_t InsecureRandBits(int bits)
Definition: random.h:25
static uint32_t InsecureRand32()
Definition: random.h:15
static bool InsecureRandBool()
Definition: random.h:35