Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/s/srand.html on line 1

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/s/srand.html on line 1

Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/s/srand.html on line 8

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/s/srand.html on line 8

srand()

Start a new sequence of pseudo-random integers

Synopsis:

#include <stdlib.h>

void srand( unsigned int seed );

Arguments:

seed
The seed of the sequence of pseudo-random integers.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

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>
#include <time.h>

int main( void )
  {
    int i;

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

    /* Start the same sequence over again. */

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

    /*
     Use the current time as a seed to
     get a different sequence.
    */

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

    return EXIT_SUCCESS;
  }

Classification:

ANSI, POSIX 1003.1

Safety:
Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes

See also:

rand()


Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/s/srand.html on line 145

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/s/srand.html on line 145