[Previous]
[Contents]
[Next]

rand()

compute a sequence of pseudo-random integers

Synopsis:

#include <stdlib.h>
int rand( void );

Description:

The rand() function computes a sequence of pseudo-random integers in the range 0 to RAND_MAX (32767). The sequence can be started at different values by calling the srand() function.

Returns:

A pseudo-random integer.

Examples:

#include <stdio.h>
#include <stdlib.h>

void main()
  {
    int i;

    for( i=1; i < 10; ++i ) {
      printf( "%d\n", rand() );
    }
  }

Classification:

ANSI

Safety:
Interrupt handler Yes
Signal handler Yes
Thread Yes

See also:

srand()


[Previous]
[Contents]
[Next]