Index of Section 3 Manual Pages
| Interix / SUA | rand.3 | Interix / SUA |
rand(3) rand(3)
rand()
NAME
rand(), rand_r(), srand() - system random number generator
SYNOPSIS
#include
void srand (unsigned seed)
int rand (void)
int rand_r (unsigned *seed)
DESCRIPTION
The rand(3) function computes a sequence of pseudo-random integers in the
range of 0 to {RAND_MAX} (as defined in the header file ).
The srand(3) function sets its argument as the seed for a new sequence of
pseudo-random numbers to be returned by rand(3). These sequences are
repeatable by calling srand(3) with the same seed value.
The reentrant rand_r(3) function computes a sequence of pseudo-random
integers in the range of 0 to {RAND_MAX}. If rand_r(3) is called with the
same initial value for the object identified by the seed argument and that
object is not modified between successive returns and calls to rand_r(3),
the same sequence is generated.
If no seed value is provided, the functions are automatically seeded with
a value of 1.
To seed the random number generator with the time (a popular source), you
can use:
srand((unsigned int)time(NULL));
SEE ALSO
random(3)
USAGE NOTES
The following functions are thread safe: rand_r, srand. The rand function
is not thread safe.
None of these functions are async-signal safe.