#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;
+
+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() {
- retry:
- auto port = random_num(5000, 32000);
- Connection conn(port);
+ do {
+ auto port = random_num(5000, 32000);
+ Connection conn(port);
- if (!conn.open()) {
- return port;
- }
- if (!conn.isOpen()) {
- return port;
- }
- goto retry;
+ if (!conn.open()) {
+ return port;
+ }
+ if (!conn.isOpen()) {
+ return port;
+ }
+ } while(true);
}
string random_port_string(const string &) {
random_ascii_string(random_num(minlen, maxlen))
};
}
+
+#include <climits>
+
+char random_binary() {
+ return random_num(CHAR_MIN, CHAR_MAX);
+}
+
+string random_binary_string(size_t len) {
+ string s;
+ s.reserve(len + 1);
+
+ for (size_t rem = 0; rem < len; ++rem) {
+ s += random_binary();
+ }
+ s[len] = 0;
+
+ return s;
+}