Fix broken random seed generation.
[alexxy/gromacs.git] / src / gromacs / random / seed.cpp
index 79f67c9cfc2edbf572ba5daf4dcff6e4f20dbbd7..f046bd96bc9672426f5da9f8bec94b1faa5fedc2 100644 (file)
@@ -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 <time.h>
+#include <chrono>
 
 #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::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
+        std::mt19937_64 prng(microsecondsSinceEpoch);
         return makeRandomSeedInternal(prng);
     }
 }