#include "testing/lib/random.hpp"
#include "testing/lib/Connection.hpp"
-#include <chrono>
-#include <random>
-
#include <unistd.h> // getpid()
-
-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>;
-
- auto time = duration_cast<nanoseconds>(system_clock::now().time_since_epoch());
- auto seed = static_cast<rnd::result_type>(time.count() % numeric_limits<T>::max());
- auto rgen = rnd{seed};
- return dst(min, max)(rgen);
-}
-
unsigned random_port() {
retry:
auto port = random_num(2<<9, 2<<15);
#pragma once
#include <cstddef>
+#include <chrono>
+#include <random>
#include <string>
#include <type_traits>
#include <utility>
using kv_pair = pair<string, string>;
template<typename T>
-enable_if_t<is_integral_v<T>, T> random_num(T min, T max);
+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>;
+
+ auto time = duration_cast<nanoseconds>(system_clock::now().time_since_epoch());
+ auto seed = static_cast<rnd::result_type>(time.count() % numeric_limits<T>::max());
+ auto rgen = rnd{seed};
+ return dst(min, max)(rgen);
+}
unsigned random_port();
string random_port_string(const string &);