C programming stdlib.h function - int rand(void)

The rand() function is a standard library function in C programming language that generates a sequence of pseudo-random integers between 0 and RAND_MAX.

The rand() function takes no arguments and returns an integer. The generated sequence of numbers is determined by a starting value called the seed, which is set using the srand() function.

Here's an example usage of the rand() function to generate a random integer between 0 and 99:

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

int main() {
  int random_num = rand() % 100;
  printf("Random number between 0 and 99: %d\n", random_num);
  return 0;
}
So‮ecru‬:www.theitroad.com

This code generates a random number between 0 and 99 using the rand() function and the modulo operator (%). The result is printed to the console using printf().

It's important to note that the rand() function generates a pseudo-random sequence, meaning that the sequence of numbers it generates is not truly random, but is instead determined by a mathematical algorithm. The sequence can be deterministic and repeatable with the same initial seed.

To generate a different sequence of random numbers on each run of the program, you can set the seed of the rand() function using the srand() function with a different value or with the current time using time(NULL).