// Copyright (c) 2023 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include #include #include #include #include #include FastRandomContext g_insecure_rand_ctx; /** Return the unsigned from the environment var if available, otherwise 0 */ static uint256 GetUintFromEnv(const std::string& env_name) { const char* num = std::getenv(env_name.c_str()); if (!num) return {}; return uint256S(num); } void Seed(FastRandomContext& ctx) { // Should be enough to get the seed once for the process static uint256 seed{}; static const std::string RANDOM_CTX_SEED{"RANDOM_CTX_SEED"}; if (seed.IsNull()) seed = GetUintFromEnv(RANDOM_CTX_SEED); if (seed.IsNull()) seed = GetRandHash(); LogPrintf("%s: Setting random seed for current tests to %s=%s\n", __func__, RANDOM_CTX_SEED, seed.GetHex()); ctx = FastRandomContext(seed); }