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
Start a new sequence of pseudo-random integers
#include <stdlib.h>
void srand( unsigned int seed );
- seed
- The seed of the sequence of pseudo-random integers.
libc
Use the -l c option to
qcc
to link against this library.
This library is usually included automatically.
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.
#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;
}
ANSI,
POSIX 1003.1
Safety: | |
Cancellation point |
No |
Interrupt handler |
No |
Signal handler |
Yes |
Thread |
Yes |
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