UUID: include 'seconds' field of current time in RNG seed

XOR the 'seconds' and 'nanoseconds' fields of the current time to seed the
RNG used for generating random UUIDs. This ensures a better seed just in
case the clock as no sub-second resolution.
This commit is contained in:
Sybren A. Stüvel
2021-09-20 12:01:59 +02:00
parent 1f51672d71
commit 4eba920d15

View File

@@ -40,7 +40,10 @@ UUID BLI_uuid_generate_random()
struct timespec ts;
timespec_get(&ts, TIME_UTC);
rng.seed(ts.tv_nsec);
/* XOR the nanosecond and second fields, just in case the clock only has seconds resolution. */
uint64_t seed = ts.tv_nsec;
seed ^= ts.tv_sec;
rng.seed(seed);
return rng;
}();