#include <stdlib.h>int rand(void);
void srand(unsigned int seed);
int rand_r(unsigned int seed);
rand_r computes a sequence of pseudo-random integers in the range 0 to RAND_MAX. If rand_r is called with the same initial value for seed and the value of seed is unchanged between successive returns and calls to rand_r, then the same sequence of random numbers are generated.
The function srand uses the argument seed as a seed for a new sequence of pseudo-random numbers to be returned by subsequent calls to the function rand. If the function srand is then called with the same seed value, the sequence of pseudo-random numbers will be repeated. If the function rand is called before any calls to srand have been made, the same sequence will be generated as when srand is first called with a seed value of 1.
Each thread that accesses one of the functions drand48, lrand48, mrand48, srand48, seed48, or lcong48 should be coded as per the following example:
mutex_lock(I_am_using_drand48); value = FUNCTION(); mutex_unlock(I_am_using_drand48);
where FUNCTION is one of those listed. The same mutex must be used for all six functions.