Rand () does not obey srand () in Qt Creator

I wrote a program in Qt Creator 1.0.0 (Qt version 4.5.0), where at the beginning of the main () function I put

srand(time(0)); 

Then I call rand () from another thread (subclass of QThread). In this function, rand () produces the same sequence of numbers every time I run the program. I do not run the program several times per second.

Why is this happening?

+4
source share
1 answer

You need to call srand in each thread, because the seed is stored in a specific thread block.

+17
source

All Articles