When you seed the random number generator, you're telling it where to start in a pseudo-random sequence, and the 'time' you seed it with has a resolution of only one second. Basically, your program guesses the same number over and over again for a full second until the time(0) property changes and it seeds using a new number. Try this code and you'll see that the computer guesses the same thing over and over, and only changes its guess once a second or so.
#include <iostream>
#include <cstdlib>
#include <ctime>
int getRandomNumber(unsignedint lowEnd, unsignedint highEnd)
{
//if the range is one number, don't bother with rand
if(lowEnd == highEnd) return lowEnd;
//swap the values if the user passed them in the wrong order
if(highEnd < lowEnd)
{
unsignedint temp = highEnd;
highEnd = lowEnd;
lowEnd = temp;
}
//stick our desired range into a variable for readibility
//add one at the end to avoid a fencepost error
unsignedint range = (highEnd - lowEnd) + 1;
//generate a number within our range and shift it up
//based on the lowest number we want to generate
return (std::rand() % range) + lowEnd;
}
int main()
{
//seed only once!
std::srand(std::time(nullptr));
for(int i = 0; i < 10; ++i)
{
//generate a random number between 7 and 13
std::cout << getRandomNumber(7, 13) << "\n";
}
return 0;
}