/
githubmirror
/
bitcoin
Обзор
Документация
Войти
/
githubmirror
/
bitcoin
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/test/util/random.h
40 строк
1 KB
MarcoFalke
fuzz: Abort when using global PRNG without re-seed
16 дек 2024, 17:23
16 дек 2024, 17:23
fa18acb
Код
Авторство
О чём код?
// Copyright (c) 2023-present The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #ifndef BITCOIN_TEST_UTIL_RANDOM_H #define BITCOIN_TEST_UTIL_RANDOM_H #include <consensus/amount.h> #include <random.h> #include <uint256.h> #include <atomic> #include <cstdint> enum class SeedRand { /** * Seed with a compile time constant of zeros. */ ZEROS, /** * Seed with a fixed value that never changes over the lifetime of this * process. The seed is read from the RANDOM_CTX_SEED environment variable * if set, otherwise generated randomly once, saved, and reused. */ FIXED_SEED, }; /** Seed the global RNG state for testing and log the seed value. This affects all randomness, except GetStrongRandBytes(). */ void SeedRandomStateForTest(SeedRand seed); extern std::atomic<bool> g_seeded_g_prng_zero; extern std::atomic<bool> g_used_g_prng; template <RandomNumberGenerator Rng> inline CAmount RandMoney(Rng&& rng) { return CAmount{rng.randrange(MAX_MONEY + 1)}; } #endif // BITCOIN_TEST_UTIL_RANDOM_H