Changeset View
Changeset View
Standalone View
Standalone View
src/test/util/setup_common.h
Show First 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | |||||
*/ | */ | ||||
extern FastRandomContext g_insecure_rand_ctx; | extern FastRandomContext g_insecure_rand_ctx; | ||||
/** | /** | ||||
* Flag to make GetRand in random.h return the same number | * Flag to make GetRand in random.h return the same number | ||||
*/ | */ | ||||
extern bool g_mock_deterministic_tests; | extern bool g_mock_deterministic_tests; | ||||
static inline void SeedInsecureRand(bool deterministic = false) { | enum class SeedRand { | ||||
g_insecure_rand_ctx = FastRandomContext(deterministic); | ZEROS, //!< Seed with a compile time constant of zeros | ||||
SEED, //!< Call the Seed() helper | |||||
}; | |||||
/** | |||||
* Seed the given random ctx or use the seed passed in via an | |||||
* environment var | |||||
*/ | |||||
void Seed(FastRandomContext &ctx); | |||||
static inline void SeedInsecureRand(SeedRand seed = SeedRand::SEED) { | |||||
if (seed == SeedRand::ZEROS) { | |||||
g_insecure_rand_ctx = FastRandomContext(/* deterministic */ true); | |||||
} else { | |||||
Seed(g_insecure_rand_ctx); | |||||
} | |||||
} | } | ||||
static inline uint32_t InsecureRand32() { | static inline uint32_t InsecureRand32() { | ||||
return g_insecure_rand_ctx.rand32(); | return g_insecure_rand_ctx.rand32(); | ||||
} | } | ||||
static inline uint256 InsecureRand256() { | static inline uint256 InsecureRand256() { | ||||
return g_insecure_rand_ctx.rand256(); | return g_insecure_rand_ctx.rand256(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 118 Lines • Show Last 20 Lines |