Skip to content

Commit

Permalink
[flang][runtime] Correct RANDOM_INIT seed generation (#106250)
Browse files Browse the repository at this point in the history
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 #106221.
  • Loading branch information
klausler authored Sep 4, 2024
1 parent 4228e28 commit 6facf69
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion flang/runtime/random.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6facf69

Please sign in to comment.