I've written a program in Qt Creator 1.0.0 (Qt version 4.5.0) where at the beginning of main() function I've put
srand(time(0));
Then I'm calling rand() from another thread (subclass of QThread). In that function, rand() is producing same sequence of numbers each time I'm running the program. I'm not running the program multiple times in a second.
Why is this happening?
You need to call srand in each thread, because the seed is stored in a thread-specific block.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With