srand

Description

Sets a random starting point.

#include <stdlib.h> Required only for function declarations  

void srand( unsigned int seed );

seed Seed for random-number generation  

Remarks

The srand function sets the starting point for generating a series of pseudorandom integers. To reinitialize the generator, use 1 as the seed argument. Any other value for seed sets the generator to a random starting point.

The rand function is used to retrieve the pseudorandom numbers that are generated. Calling rand before any call to srand will generate the same sequence as calling srand with seed passed as 1.

Return Value

None.

Compatibility

Standards:ANSI, UNIX

16-Bit:DOS, QWIN, WIN, WIN DLL

32-Bit:DOS32X

See Also

rand

Example

/* RAND.C: This program seeds the random number generator with the

* time, then displays 20 random integers.

*/

#include <stdlib.h>

#include <stdio.h>

#include <time.h>

void main( void )

{

int i;

/* Seed the random number generator with current time so that

* the numbers will be different every time we run.

*/

srand( (unsigned)time( NULL ) );

/* Display 10 numbers. */

for( i = 0; i < 10; i++ )

printf( " %6d\n", rand() );

}

Output

19471

16395

8268

15582

6489

28356

27042

5276

23070

10930