Skip to content

Commit

Permalink
Use steady_clock to generate the seed for srand
Browse files Browse the repository at this point in the history
And remove outdates comments.
  • Loading branch information
quink-black committed Apr 13, 2021
1 parent 8befa35 commit 2443cb3
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions srtcore/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 2443cb3

Please sign in to comment.