I want to generate 3 random numbers by calling a function which generates a number 3 times. The function is:
1 2 3 4 5 6 7 8 9
int randomgetal()
{
int getal;
srand(time(0));
getal = 2+ rand() % 6;
return getal;
}
Very easy. First of all, can anyone explain me the meaning of (0) in the time() function in there? I got it from a tutorial. Also, the compiler gives me this warning:
warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
Why is that and is there a way to solve it?
Now my real problem... just calling this function 3 times doesn't work because it has the same system time and so generates 3 times the same number. What's the best way to let it generate 3 random numbers (they may be the same)?
Bazzy spoke too quickly here. The 0 in time(0) is actually a null pointer. time() will write its result to the given address as well as return it if this pointer is non-null.