Statically initialize mersenne twister for UUID::Random()
By re-seeding the pseudo-random number generator on every call to
Random() we were effectively limiting ourselves to at most 2 ** 32
possible UUIDs (because std::random_device only produces 32 bits).
By making the pseudo-random number generator thread_local, subsequent
calls to UUID::Random() in the same thread will cover additional bit
space and get us closer to an "actual" 128 bits of randomness.
This alone is *probably* sufficient to remove any potential for hash
collisions in the foreseeable future, but we probably should more
properly initialize the random number generator.
Change-Id: I24be8e7a750337237a24a178ae5078af6ae3d8d8
Signed-off-by: James Kuszmaul <james.kuszmaul@bluerivertech.com>
diff --git a/aos/BUILD b/aos/BUILD
index 396d107..6a45949 100644
--- a/aos/BUILD
+++ b/aos/BUILD
@@ -713,6 +713,16 @@
)
cc_test(
+ name = "uuid_collision_test",
+ srcs = ["uuid_collision_test.cc"],
+ target_compatible_with = ["@platforms//os:linux"],
+ deps = [
+ ":uuid",
+ "//aos/testing:googletest",
+ ],
+)
+
+cc_test(
name = "uuid_test",
srcs = ["uuid_test.cc"],
target_compatible_with = ["@platforms//os:linux"],