Go to the previous, next section.

ANSI C Random Number Functions

This section describes the random number functions that are part of the ANSI C standard.

To use these facilities, you should include the header file `stdlib.h' in your program.

Macro: int RAND_MAX

The value of this macro is an integer constant expression that represents the maximum possible value returned by the rand function. In the GNU library, it is 037777777, which is the largest signed integer representable in 32 bits. In other libraries, it may be as low as 32767.

Function: int rand ()

The rand function returns the next pseudo-random number in the series. The value is in the range from 0 to RAND_MAX.

Function: void srand (unsigned int seed)

This function establishes seed as the seed for a new series of pseudo-random numbers. If you call rand before a seed has been established with srand, it uses the value 1 as a default seed.

To produce truly random numbers (not just pseudo-random), do srand (time (0)).

Go to the previous, next section.