i know that when srand() function is called inside a loop it will generate different random numbers, since srand() is inside the loop and the loop is likely done less than a second, therefore we have the same numbers every time.
my question is here: why  when the  srand() is out of the loop it works properly?
if the loop is completed less than a second, therefore the seed is again, the same for all numbers...but it changes every time. though the seed is seem to stay the same.
 try the following code:
int k = 5;
while (k--)
{
    srand(time(0));
    int num1 = rand() % 6;
    cout << num1 << endl;
}
 
    