rand, irand, srand - random number generator
integer iseed, i, irand
double precision x, rand
i = irand( )
x = rand( )
Irand generates successive pseudo-random integers in the range from 0 to
2**15-1. rand generates pseudo-random numbers distributed in [0, 1.0].
Srand uses its integer argument to re-initialize the seed for successive
invocations of irand and rand.
rand, srand, rand_r - simple random-number generator
int rand (void);
int rand_r (unsigned int *seed);
void srand (unsigned int seed);
rand uses a multiplicative congruent random-number generator with period
2^32 that returns successive pseudo-random numbers in the range from 0 to
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.
rand_r is a reentrant version of rand. If rand_r is called with the same
initial value for *seed and the value of *seed is not changed between
successive returns and calls to rand_r, the same sequence shall be
generated. This function is useful when multiple threads in a process
each wish to get their own repeatable pseudo-random number sequence. The
feature test macro _SGI_REENTRANT_FUNCTIONS should be defined to make
this function visible.
The spectral properties of rand are limited. drand48(3C) and random(3B)
provide a much better, though more elaborate, random-number generator.
In a multi-threaded program rand is made MP safe by single-threading
access to the shared seed. For best performance threaded applications
should use rand_r instead.
PPPPaaaaggggeeee 1111 [ Back ]