diff --git a/src/console_commands.cpp b/src/console_commands.cpp index a0a011e..84f087e 100644 --- a/src/console_commands.cpp +++ b/src/console_commands.cpp @@ -85,9 +85,10 @@ ConsoleCommands::ConsoleCommands(p2pool* pool) } std::random_device rd; + std::mt19937_64 rng(rd()); for (int i = 0; i < 10; ++i) { - if (start_listening(false, "127.0.0.1", 49152 + (rd() % 16384))) { + if (start_listening(false, "127.0.0.1", 49152 + (rng() % 16384))) { break; } } diff --git a/src/merge_mining_client_tari.cpp b/src/merge_mining_client_tari.cpp index 285e6df..1627578 100644 --- a/src/merge_mining_client_tari.cpp +++ b/src/merge_mining_client_tari.cpp @@ -453,9 +453,10 @@ MergeMiningClientTari::TariServer::TariServer(const std::string& socks5Proxy) bool MergeMiningClientTari::TariServer::start() { std::random_device rd; + std::mt19937_64 rng(rd()); for (size_t i = 0; i < 10; ++i) { - if (start_listening(false, "127.0.0.1", 49152 + (rd() % 16384))) { + if (start_listening(false, "127.0.0.1", 49152 + (rng() % 16384))) { break; } } diff --git a/src/zmq_reader.cpp b/src/zmq_reader.cpp index 2bd26f7..736d1da 100644 --- a/src/zmq_reader.cpp +++ b/src/zmq_reader.cpp @@ -42,9 +42,10 @@ ZMQReader::ZMQReader(const std::string& address, uint32_t zmq_port, const std::s addr_buf[0] = '\0'; std::random_device rd; + std::mt19937_64 rng(rd()); for (uint32_t i = 0; i < 100; ++i) { - const uint32_t port = 49152 + (rd() % 16384); + const uint32_t port = 49152 + (rng() % 16384); try { log::Stream s(addr_buf); @@ -215,6 +216,7 @@ bool ZMQReader::connect(const std::string& address, bool keep_monitor) if (!id) { std::random_device rd; id = (static_cast(rd()) << 32) | static_cast(rd()); + id >>= 1; // to avoid MAX_UINT64 case } char buf[64];