Use CLOCK_REALTIME for providing the initial seed value

CLOCK_MONOTONIC is specified as returning time "since an unspecified point in the past". On RISC OS with UnixLib this returns the time since the last hard reset, but with SharedCLibrary this returns the time since the program started - combined with the coarse resolution used internally, this almost always results in a seed of 0.

CLOCK_REALTIME meanwhile is specified as returning time since the epoch, so it should behave consistently across all platforms.
This commit is contained in:
Cameron Cawley
2025-11-22 23:30:02 +00:00
parent 04d588ee94
commit 28b165940d
2 changed files with 2 additions and 2 deletions
+1 -1
View File
@@ -644,7 +644,7 @@ static unsigned get_seed(void) {
return (unsigned) mach_absolute_time();
#else
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
clock_gettime(CLOCK_REALTIME, &ts);
return (unsigned) (1000000000ULL * ts.tv_sec + ts.tv_nsec);
#endif
}
+1 -1
View File
@@ -62,7 +62,7 @@ static unsigned get_seed(void) {
return (unsigned) mach_absolute_time();
#elif HAVE_CLOCK_GETTIME
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
clock_gettime(CLOCK_REALTIME, &ts);
return (unsigned) (1000000000ULL * ts.tv_sec + ts.tv_nsec);
#endif
}