Yes, I did a search, and I understand time() better than before, but I would appreciate personal help.
Initially, I wanted to make a program/function that would randomly generate a number. Next, I wanted to limit it between two defined numbers. I came across rand() yesterday, and I couldn't get it to work. I realized rand() had to be seeded with the function srand(), and the most preferred source was time, following being the code
#include <time>
#include <iostream>
#include <cstdlib>
int main()
{
int random;
srand(time(null));
random=rand() % 51;
cout<<"\nA random number not greater than 50? Well, what about "<<random<<"?";
return 0;
}
My doubt is at line 9. From what I have studied in my school so far, % finds and assigns the remainder of an expression. So, if time is calculated since 1-Jan-1970, how does dividing the seconds passed by until that day by 51, give a number between 0 and 50?
Or is this a piece of code specifically for rand() function?