Question: Description: Write a program which displays a number between 10 to 100 randomly. Hint: Use cstdlib and ctime library functions like rand() , e.g. srand(time(0));
Description:
Write a program which displays a number between 10 to 100 randomly.



Hint:
Use cstdlib and ctime library functions like rand(), e.g.
srand(time(0)); // First, "Seed" the random generator
srand() gives the random function a new seed, a starting point (usually random numbers are calculated by taking the previous number (or the seed) and then do many operations on that number to generate the next).
time(0) gives the time in seconds since the Unix epoch (the Unix epoch = 1 January 1970 00:00:00. time(0) returns the amount of seconds that have passed since that moment) which is a pretty good "unpredictable" seed (you're guaranteed your seed will be the same only once, unless you start your program multiple times within the same second).
Thus its better than using (time(NULL)), which is likely to return the same random numbers always within a second.
rand()%91 + 10; // Randomly generate integer between 10 and 100
The randomly selected number is : 34 The randomly selected number is : 45 The randomly selected number is : 76
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
