thread safe randoms
[awesomized/libmemcached] / test / lib / random.cpp
index 6aab887597f087e75b823f24773cf0515845c11d..1d9a20c9a9b166e0b5beda1743a04e5ffcfcb906 100644 (file)
@@ -3,6 +3,16 @@
 
 #include <unistd.h> // getpid()
 
+mt19937_64 rnd_eng;
+mutex rnd_mtx;
+
+void random_setup() {
+  using namespace chrono;
+
+  auto time = duration_cast<nanoseconds>(system_clock::now().time_since_epoch());
+  rnd_eng.seed(static_cast<mt19937_64::result_type>(time.count()));
+}
+
 unsigned random_port() {
   do {
     auto port = random_num(5000, 32000);