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:
@@ -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;
|
||||
}();
|
||||
|
||||
Reference in New Issue
Block a user