Hi, I am trying to develop a random number generator that will generate a series of numbers between 1000 and 9999. I can't figure out what I have to do. Can someone point me in the proper direction.
#include <iostream>
#include <cstdlib>
#include <ctime>
usingnamespace std;
int main ()
{
int f;
char s;
int l;
cout << "Begin" << endl;
for (int d = 0; d < 5; d++) {
for (int i = 0; i < 4; i++)
{
l = rand();
}
f = (rand() % 26);
s = (char) (f+ 65);
cout << l << s << endl;
}
}
I haven't looked too much into it, but I can give you a quick explanation.
time() takes in a pointer to a time_t object, which then stores whatever value you passed into it. In this case passing NULL into the time function shows that you don't want to store a specific time_t object, and it should just use it's own default value (which in this case is the amount of seconds that have passed since January 1st 1970 I believe).
This is a good value to use for srand as it is always changing, you could just do srand(10) but the program would always output the same number whenever you ran it.