From 818c05a2f0da059dce50a06ce1dd1a69cf4305a1 Mon Sep 17 00:00:00 2001 From: Kevin Boyd Date: Wed, 30 Dec 2020 09:51:25 -0800 Subject: [PATCH] Fix broken random seed generation. On Ryzen 3k CPUs with the RDRAND microcode bug, the std::mt19937_64 alternate path yields the same seed on multiple calls that fall within the same second. Changed the "seed" of the random seed to rescramble each time the makeRandomSeed() function is called. Fixes #3859 --- src/gromacs/random/seed.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/gromacs/random/seed.cpp b/src/gromacs/random/seed.cpp index 79f67c9cfc..f046bd96bc 100644 --- a/src/gromacs/random/seed.cpp +++ b/src/gromacs/random/seed.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2015,2016,2018,2019,2020, by the GROMACS development team, led by + * Copyright (c) 2015,2016,2018,2019,2020,2021, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -37,7 +37,7 @@ #include "seed.h" -#include +#include #include "gromacs/utility/basedefinitions.h" #include "gromacs/utility/fatalerror.h" @@ -111,7 +111,8 @@ uint64_t makeRandomSeed() } else { - std::mt19937_64 prng(time(nullptr)); + int64_t microsecondsSinceEpoch = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); + std::mt19937_64 prng(microsecondsSinceEpoch); return makeRandomSeedInternal(prng); } } -- 2.22.0