#include "test/lib/random.hpp"
#include "test/lib/Connection.hpp"
-#include <unistd.h> // getpid()
+#if HAVE_UNISTD_H
+# include <unistd.h> // getpid()
+#endif
+mt19937_64 rnd_eng;
+mutex rnd_mtx;
-unsigned random_port() {
- retry:
- auto port = random_num(5000, 32000);
- Connection conn(port);
+void random_setup() {
+ using namespace chrono;
- if (!conn.open()) {
- return port;
- }
- if (!conn.isOpen()) {
- return port;
- }
- goto retry;
+ 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);
+ Connection conn(port);
+
+ if (!conn.open()) {
+ return port;
+ }
+ if (!conn.isOpen()) {
+ return port;
+ }
+ } while(true);
}
string random_port_string(const string &) {