#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);
#include <string>
#include <type_traits>
#include <utility>
+#include <mutex>
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();
#include "mem_config.h"
#include "test/lib/env.hpp"
+#include "test/lib/random.hpp"
#include <cstdlib>
#include <cstdio>
#include <cstring>
#endif
int setup(int &, char ***argv) {
+ random_setup();
+
setup_signals();
setup_asan(*argv);
setup_sasl();