[flang-commits] [flang] 6facf69 - [flang][runtime] Correct RANDOM_INIT seed generation (#106250)
via flang-commits
flang-commits at lists.llvm.org
Wed Sep 4 10:52:28 PDT 2024
Author: Peter Klausler
Date: 2024-09-04T10:52:20-07:00
New Revision: 6facf6981488700c1554dcce36d4ac774a91d568
URL: https://github.com/llvm/llvm-project/commit/6facf6981488700c1554dcce36d4ac774a91d568
DIFF: https://github.com/llvm/llvm-project/commit/6facf6981488700c1554dcce36d4ac774a91d568.diff
LOG: [flang][runtime] Correct RANDOM_INIT seed generation (#106250)
The initial seed was generated from a bitwise AND ("&") of two
clock-generated values, instead of an XOR or (best) a truncated integer
multiplication. Maybe I mistyped a shift-7 instead of a shift-6 or
shift-8 when I wrote that line, but it was most likely just stupidity.
Fixes https://github.com/llvm/llvm-project/issues/106221.
Added:
Modified:
flang/runtime/random.cpp
Removed:
################################################################################
diff --git a/flang/runtime/random.cpp b/flang/runtime/random.cpp
index e0a421fd283962..69de9b8c96fb5d 100644
--- a/flang/runtime/random.cpp
+++ b/flang/runtime/random.cpp
@@ -42,7 +42,7 @@ void RTNAME(RandomInit)(bool repeatable, bool /*image_distinct*/) {
#ifdef CLOCK_REALTIME
timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
- generator.seed(ts.tv_sec & ts.tv_nsec);
+ generator.seed(ts.tv_sec ^ ts.tv_nsec);
#else
generator.seed(time(nullptr));
#endif
More information about the flang-commits
mailing list