projects
/
awesomized
/
libmemcached
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
|
github
raw
|
inline
| side by side
libmemcached: fix #125: allocation failure on negative expiration
[awesomized/libmemcached]
/
test
/
lib
/
random.hpp
diff --git
a/test/lib/random.hpp
b/test/lib/random.hpp
index 723146a9acd07a31e24f9b2deb1c77d522d7eb92..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_64;
- using dst = uniform_int_distribution<uintmax_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());
- 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();