C programming stdlib.h function - void srand(unsigned int seed)

The srand() function is a standard library function in C programming language that sets the seed value for the rand() function, which is used to generate pseudo-random numbers.

The srand() function takes a single argument, an unsigned integer value that serves as the new seed for the rand() function. Here's an example usage of the srand() function:

ref‮i:ot re‬giftidea.com
#include <stdlib.h>
#include <stdio.h>
#include <time.h>

int main() {
  srand(time(NULL));
  int random_num = rand() % 100;
  printf("Random number between 0 and 99: %d\n", random_num);
  return 0;
}

In this example, the srand() function is used to set the seed value for the rand() function using the current time as the argument. This ensures that the sequence of random numbers generated by the rand() function is different on each run of the program.

It's important to note that the srand() function should only be called once at the beginning of the program, and not repeatedly throughout the program, in order to avoid generating predictable and repetitive sequences of pseudo-random numbers.