rand
Defined in header
<stdlib.h>


int rand();


Returns a pseudorandom integral value between 0 and RAND_MAX (0 and RAND_MAX
included).
srand() seeds the pseudorandom number generator used by rand()
.
If rand()
is used before any calls to srand()
, rand()
behaves as if it was seeded with srand(1)
.
Each time rand()
is seeded with srand()
, it must produce the same sequence of values.
rand()
is not guaranteed to be threadsafe.
Contents 
[edit] Parameters
(none)
[edit] Return value
Pseudorandom integral value between 0 and RAND_MAX, inclusive.
[edit] Notes
There are no guarantees as to the quality of the random sequence produced.
In the past, some implementations of rand()
have had serious shortcomings in the randomness, distribution and period of the sequence produced (in one wellknown example, the loworder bit simply alternated between 1
and 0
between calls).
rand()
is not recommended for serious randomnumber generation needs, like cryptography.
POSIX requires that the period of the pseudorandom number generator used by rand
is at least 232
POSIX offered a threadsafe version of rand called rand_r, which is obsolete in favor of the drand48 family of functions.
[edit] Example
Possible output:
Random value on [0 2147483647]: 1373858591
[edit] See also
seeds pseudorandom number generator (function) 

maximum possible value generated by rand() (macro constant) 

C++ documentation for rand
