From 4eba920d15183e73ab8c2c9986b621aec4cbeca9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Mon, 20 Sep 2021 12:01:59 +0200 Subject: 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. --- source/blender/blenlib/intern/uuid.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'source/blender/blenlib') diff --git a/source/blender/blenlib/intern/uuid.cc b/source/blender/blenlib/intern/uuid.cc index 0c381e5dcd2..247928893f3 100644 --- a/source/blender/blenlib/intern/uuid.cc +++ b/source/blender/blenlib/intern/uuid.cc @@ -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; }(); -- cgit v1.2.3