All random numbers generated via one PRNG seeded in one place.
[invirt/third/libt4.git] / rpc / rpc.cc
index 2889db9..5d28f8f 100644 (file)
 using std::list;
 using namespace std::chrono;
 
-inline void set_rand_seed() {
-    auto now = time_point_cast<nanoseconds>(steady_clock::now());
-    srandom((uint32_t)now.time_since_epoch().count()^(uint32_t)getpid());
-}
-
 static sockaddr_in make_sockaddr(const string & hostandport);
 
 rpcc::rpcc(const string & d) : dst_(make_sockaddr(d))
 {
-    set_rand_seed();
-    clt_nonce_ = (nonce_t)random();
+    clt_nonce_ = (nonce_t)global->random_generator();
 
     char *loss_env = getenv("RPC_LOSSY");
     if (loss_env)
@@ -335,8 +329,7 @@ compress:
 
 rpcs::rpcs(in_port_t p1) : port_(p1)
 {
-    set_rand_seed();
-    nonce_ = (nonce_t)random();
+    nonce_ = (nonce_t)global->random_generator();
     IF_LEVEL(2) LOG << "created with nonce " << nonce_;
 
     reg(rpc_protocol::bind, &rpcs::rpcbind, this);