From: Kevin Boyd Date: Wed, 30 Dec 2020 17:51:25 +0000 (-0800) Subject: Fix broken random seed generation. X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=commitdiff_plain;h=818c05a2f0da059dce50a06ce1dd1a69cf4305a1;p=alexxy%2Fgromacs.git 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 --- 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); } }