Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems of using srand() in libraries

There is a wide use of srand()/rand() calls in 3rd party libraries, with predefined seeds. The problem arises when combining different libraries in the same process. Sometimes it's hard to ensure the right sequence of calls, a mix of srand() and rand() calls is possible. Another problem is inability to choose seeding value on application level. As a general rule, should we avoid using srand() in libraries (including Open Source), leaving the task of seeding to applications?

like image 907
David Khosid Avatar asked Nov 12 '22 11:11

David Khosid


1 Answers

For the reasons you mentioned, among others, it's better practice in real life applications to use boost::random or C++11 random library

like image 64
eladidan Avatar answered Nov 15 '22 04:11

eladidan