srand Function

Specifies a seed to be used by subsequent calls to the rand function.

Include

<stdlib.h>

Prototype

int srand(unsigned int seed);

Argument

seed
the seed to begin the sequence

Remarks

The srand function allows the seed for a pseudo-random number sequence to be specified, so that subsequent calls to the rand function will return a sequence based on that seed. The same sequence can be repeated by calling srand again with the same seed value.

Example

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

int main(void)
{
  int value;

  srand(0x100);
  value = rand();
  printf("Today's lucky number is %d\n", value);
}

Example Output

Today's lucky number is 663