#include <stdlib.h>int rand(void);
The rand() function uses a multiplicative congruential random-number generator with period 232 that returns successive pseudo-random numbers in the range of 0 to RAND_MAX (defined in <stdlib.h>).
The srand() function uses the argument seed as a seed for a new sequence of pseudo-random numbers to be returned by subsequent calls to rand(). If srand() is then called with the same seed value, the sequence of pseudo-random numbers will be repeated. If 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.
The rand_r() function has the same functionality as rand() except that a pointer to a seed seed must be supplied by the caller. The seed to be supplied is not the same seed as in srand().
The spectral properties of rand() are limited. The drand48(3C) function provides a better, more elaborate random-number generator.
The rand() is unsafe in multithreaded applications. The rand_r() function is MT-Safe, and should be used instead. The srand() function is unsafe in multithreaded applications.
When compiling multithreaded applications, the _REENTRANT flag must be defined on the compile line. This flag should only be used in multithreaded applications.
See attributes(5) for descriptions of the following attributes:
|ATTRIBUTE TYPE||ATTRIBUTE VALUE|
|MT-Level||See USAGE above.|