projects
/
awesomized
/
libmemcached
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
|
github
raw
|
inline
| side by side
cpack: generate the shell install only on UNIX
[awesomized/libmemcached]
/
test
/
lib
/
random.hpp
diff --git
a/test/lib/random.hpp
b/test/lib/random.hpp
index 1d7f7a6f7973d7ae2496b5c882d1e8926d177f89..322de6af91392b59fede7d91945039fcc299e6fb 100644
(file)
--- a/
test/lib/random.hpp
+++ b/
test/lib/random.hpp
@@
-22,22
+22,21
@@
#include <string>
#include <type_traits>
#include <utility>
#include <string>
#include <type_traits>
#include <utility>
+#include <mutex>
using namespace std;
using kv_pair = pair<string, string>;
using namespace std;
using kv_pair = pair<string, string>;
-template<typename T>
-enable_if_t<is_integral_v<T>, T> random_num(T min, T max) {
- using namespace chrono;
- using rnd = mt19937;
- using dst = uniform_int_distribution<T>;
+extern mt19937_64 rnd_eng;
+extern mutex rnd_mtx;
- static auto time = duration_cast<nanoseconds>(system_clock::now().time_since_epoch());
- static auto seed = static_cast<rnd::result_type>(time.count() % numeric_limits<T>::max());
- static auto rgen = rnd{seed};
+void random_setup();
- return dst(min, max)(rgen);
+template<typename T>
+enable_if_t<is_integral_v<T>, T> random_num(T min, T max) {
+ lock_guard m{rnd_mtx};
+ return uniform_int_distribution<T>(min, max)(rnd_eng);
}
unsigned random_port();
}
unsigned random_port();