[flang-commits] [flang] [flang][runtime] Correct RANDOM_INIT seed generation (PR #106250)

via flang-commits flang-commits at lists.llvm.org
Tue Aug 27 10:11:02 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-runtime

Author: Peter Klausler (klausler)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/106250.diff


1 Files Affected:

- (modified) flang/runtime/random.cpp (+1-1) 


``````````diff
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

``````````

</details>


https://github.com/llvm/llvm-project/pull/106250


More information about the flang-commits mailing list