Assuming you are using a C rand library function, this function is not reentrant or thread safe. POSIX provides the rand_r function, but (to quote glibc documentation):
POSIX.1 extended the standard C functions to support reproducible random numbers in multi-threaded programs. However, the extension is poorly designed and unsuitable for serious work.
In particular, the seed must be an unsigned int that does not have enough bits for a good PRNG. They recommend using SVID random number functions, of which nrand48_r is probably what you are looking for.
Alternatively, you can use another library.
source share