[Previous]
[Contents]
[Next]

srand()

start a new sequence of pseudo-random integers

Synopsis:

#include <stdlib.h>
void srand( unsigned int seed );

Description:

The srand() function uses the argument seed to start a new sequence of pseudo-random integers to be returned by subsequent calls to rand(). A particular sequence of pseudo-random integers can be repeated by calling srand() with the same seed value. The default sequence of pseudo-random integers is selected with a seed value of 1.

Examples:

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

void main()
  {
    int i;

    srand( 982 );
    for( i = 1; i < 10; ++i ) {
      printf( "%d\n", rand() );
    }
    srand( 982 );  /* start sequence over again */
    for( i = 1; i < 10; ++i ) {
      printf( "%d\n", rand() );
    }
  }

Classification:

ANSI

Safety:
Interrupt handler Yes
Signal handler Yes
Thread Yes

See also:

rand()


[Previous]
[Contents]
[Next]