Is there a function to generate a random int number in C? Or will I have to use a third party library?
C Program to generate random number between 9 and 50
#include
#include
int main()
{
srand(time(NULL));
int lowerLimit = 10, upperLimit = 50;
int r = lowerLimit + rand() % (upperLimit - lowerLimit);
printf("%d", r);
}
In general we can generate a random number between lowerLimit and upperLimit-1
i.e lowerLimit is inclusive or say r ∈ [ lowerLimit, upperLimit )