Random number generator in c

As C does not have an inbuilt function for generating a number in the range, but it does have rand function which generate a random number from 0 to RAND_MAX. With the help of rand () a number in range can be generated as num = (rand() % (upper – lower + 1)) + lower.
When we use the rand() function in a program, we need to implement the stdlib.h header file because rand() function is defined in the stdlib header file. It does not contain any seed number. Therefore, when we execute the same program again and again, it returns the same values.
Syntax-
int rand (void)                        
Example program-
#include<studio.h>
#include<stdlib.h>
void main()
{
       printf("random num generated is %d\n",rand());
 }

Output will be
random num generated is 1804289383
Posted on by