Problems using srand () in libraries

There is widespread use of calls srand()/rand()in third-party libraries with predefined seeds. The problem arises when combining different libraries into the same process. Sometimes it is difficult to ensure the correct sequence of calls, a combination of srand()and is possible rand(). Another problem is the inability to select the seed value at the application level. Generally, should libraries (including Open Source) be avoidedsrand() , leaving the seeding task to applications?

+5
source share
2 answers

For the reasons you mentioned, among others, it is better to practice using a library boost::randomor C ++ 11 in real applicationsrandom

+1
source

If the library uses hard-coded seeds, then yes, you MUST have a way to change these seeds to what you declare "random" to be a seed.

Also, if you are using a platform that has something like / dev / urand, you can probably use it, or if you need to be multi-platform, why not use something like an OpenSSL random number library? OpenSSL should probably be available on every platform that you are targeting, and often it is already installed, so you just need to link it.

0
source

All Articles