Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren@blender.org>2021-09-20 13:01:59 +0300
committerSybren A. Stüvel <sybren@blender.org>2021-09-20 13:10:25 +0300
commit4eba920d15183e73ab8c2c9986b621aec4cbeca9 (patch)
tree58e711e1acecb279406c177e66548a590feca67d /source/blender/blenlib/intern/uuid.cc
parent1f51672d7126d8c0a0b962060c01632e6e07dd5f (diff)
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.
Diffstat (limited to 'source/blender/blenlib/intern/uuid.cc')
-rw-r--r--source/blender/blenlib/intern/uuid.cc5
1 files changed, 4 insertions, 1 deletions
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;
}();