diff --git a/onnxruntime/core/framework/random_seed.cc b/onnxruntime/core/framework/random_seed.cc index 1951f88c62c65..abf566e2a91cf 100644 --- a/onnxruntime/core/framework/random_seed.cc +++ b/onnxruntime/core/framework/random_seed.cc @@ -9,23 +9,18 @@ namespace onnxruntime { namespace utils { -// "Global initializer calls a non-constexpr function." -// TODO: Fix the warning. The variable should be put in the environment class. -#if defined(_MSC_VER) && !defined(__clang__) -#pragma warning(push) -#pragma warning(disable : 26426) -#endif -static std::atomic g_random_seed(std::chrono::system_clock::now().time_since_epoch().count()); -#if defined(_MSC_VER) && !defined(__clang__) -#pragma warning(pop) -#endif +static std::atomic& GetGlobalRandomSeed() { + static std::atomic g_random_seed( + std::chrono::system_clock::now().time_since_epoch().count()); + return g_random_seed; +} int64_t GetRandomSeed() { - return g_random_seed.load(); + return GetGlobalRandomSeed().load(); } void SetRandomSeed(int64_t seed) { - g_random_seed.store(seed); + GetGlobalRandomSeed().store(seed); // Reset default generators. RandomGenerator::Default().SetSeed(seed);