From: Artem Zhmurov Date: Fri, 9 Oct 2020 15:08:45 +0000 (+0000) Subject: Cool quote picking can freeze when hardware random number generation is not working X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=commitdiff_plain;h=3491843372177f70cdecdaee206674978479a198;p=alexxy%2Fgromacs.git Cool quote picking can freeze when hardware random number generation is not working The bug with hardware random number generation can cause picking of cool quotes to freeze in an infinite loop on some Ryzen systems. This patch checks the system for the bug and falls back to PRNGs. --- diff --git a/src/gromacs/utility/coolstuff.cpp b/src/gromacs/utility/coolstuff.cpp index 3f42a264f0..55c80cd1cd 100644 --- a/src/gromacs/utility/coolstuff.cpp +++ b/src/gromacs/utility/coolstuff.cpp @@ -74,9 +74,9 @@ bool beCool() //! Return a valid random index into \c arrayRef template -const T& getRandomElement(gmx::ArrayRef arrayRef) +const T& getPseudoRandomElement(gmx::ArrayRef arrayRef) { - std::random_device generator; + std::mt19937_64 generator; std::uniform_int_distribution distribution(0, arrayRef.size() - 1); return arrayRef[distribution(generator)]; } @@ -116,7 +116,7 @@ std::string bromacs() if (beCool()) { - return getRandomElement(bromacsArray); + return getPseudoRandomElement(bromacsArray); } else { @@ -1586,7 +1586,7 @@ std::string getCoolQuote() if (beCool()) { - auto quote = getRandomElement(quoteArray); + auto quote = getPseudoRandomElement(quoteArray); return formatString("GROMACS reminds you: \"%s\" (%s)", quote.text, quote.author); } else