From 2443cb3e195d2cac7e8472fede29b052b1ae4c20 Mon Sep 17 00:00:00 2001 From: Zhao Zhili Date: Thu, 1 Apr 2021 17:52:57 +0800 Subject: [PATCH] Use steady_clock to generate the seed for srand And remove outdates comments. --- srtcore/api.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/srtcore/api.cpp b/srtcore/api.cpp index 3ba4116cb5..eca60aece1 100644 --- a/srtcore/api.cpp +++ b/srtcore/api.cpp @@ -194,14 +194,8 @@ m_bGCStatus(false), m_ClosedSockets() { // Socket ID MUST start from a random value - // Note. Don't use CTimer here, because s_UDTUnited is a static instance of CUDTUnited - // with dynamic initialization (calling this constructor), while CTimer has - // a static member s_ullCPUFrequency with dynamic initialization. - // The order of initialization is not guaranteed. - timeval t; - - gettimeofday(&t, 0); - srand((unsigned int)t.tv_usec); + unsigned seed = count_microseconds(steady_clock::now().time_since_epoch()) & UINT32_MAX; + srand(seed); const double rand1_0 = double(rand())/RAND_MAX;