diff --git a/flang/runtime/random.cpp b/flang/runtime/random.cpp index b7175d6b63c35..8b00cfd1cac19 100644 --- a/flang/runtime/random.cpp +++ b/flang/runtime/random.cpp @@ -20,10 +20,10 @@ #include #include #include -#include #include #include #include +#include namespace Fortran::runtime { @@ -100,7 +100,13 @@ void RTNAME(RandomInit)(bool repeatable, bool /*image_distinct*/) { if (repeatable) { generator.seed(0); } else { - generator.seed(std::time(nullptr)); +#ifdef CLOCK_REALTIME + timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + generator.seed(ts.tv_sec & ts.tv_nsec); +#else + generator.seed(time(nullptr)); +#endif } } }