[flang-commits] [flang] [flang][runtime] Correct RANDOM_INIT seed generation (PR #106250)
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Tue Aug 27 10:10:28 PDT 2024
https://github.com/klausler created https://github.com/llvm/llvm-project/pull/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.
>From 7823283f09914b2076c6678846fbf4a877332e50 Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Tue, 27 Aug 2024 10:07:00 -0700
Subject: [PATCH] [flang][runtime] Correct RANDOM_INIT seed generation
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.
---
flang/runtime/random.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/flang/runtime/random.cpp b/flang/runtime/random.cpp
index e0a421fd283962..360570eeef19e3 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