Bitcoin Core 28.0.0
P2P Digital Currency
Loading...
Searching...
No Matches
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 <uint256.h>
11
12#include <cstdint>
13
21
22enum class SeedRand {
23 ZEROS,
24 SEED,
25};
26
29
30static inline uint32_t InsecureRand32()
31{
33}
34
35static inline uint256 InsecureRand256()
36{
38}
39
40static inline uint64_t InsecureRandBits(int bits)
41{
42 return g_insecure_rand_ctx.randbits(bits);
43}
44
45static inline uint64_t InsecureRandRange(uint64_t range)
46{
47 return g_insecure_rand_ctx.randrange(range);
48}
49
50static inline bool InsecureRandBool()
51{
53}
54
56{
57 return static_cast<CAmount>(InsecureRandRange(MAX_MONEY + 1));
58}
59
60#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
Fast randomness source.
Definition random.h:377
I randrange(I range) noexcept
Generate a random integer in the range [0..range), with range > 0.
Definition random.h:254
uint256 rand256() noexcept
generate a random uint256.
Definition random.h:308
bool randbool() noexcept
Generate a random boolean.
Definition random.h:316
uint32_t rand32() noexcept
Generate a random 32-bit integer.
Definition random.h:305
uint64_t randbits(int bits) noexcept
Generate a random (bits)-bit integer.
Definition random.h:204
256-bit opaque blob.
Definition uint256.h:178
void SeedRandomForTest(SeedRand seed=SeedRand::SEED)
Seed the RNG for testing.
Definition random.cpp:18
SeedRand
Definition random.h:22
@ ZEROS
Seed with a compile time constant of zeros.
@ SEED
Use (and report) random seed from environment, or a (truly) random one.
static CAmount InsecureRandMoneyAmount()
Definition random.h:55
static uint64_t InsecureRandRange(uint64_t range)
Definition random.h:45
static uint256 InsecureRand256()
Definition random.h:35
static uint64_t InsecureRandBits(int bits)
Definition random.h:40
static uint32_t InsecureRand32()
Definition random.h:30
FastRandomContext g_insecure_rand_ctx
This global and the helpers that use it are not thread-safe.
Definition random.cpp:14
static bool InsecureRandBool()
Definition random.h:50