Generate a random number as usual, if it's already been used try again, otherwise return the random number. You should also remember to call srand(time(NULL)), otherwise the same random sequence will be generated between runs
e.g
1 2 3 4 5 6 7 8 9 10 11 12
int generateUniqueInt()
{
static vector<int> generatedValues;
int num = rand() % tam;
while(contains(generatedValues, num)) //You'll need a function to check whether the num is in this vector
{
num = rand() % tam;
}
return num;
}
You'll also have to make sure to add the number to your list of generatedValues each time you find a new value.
This also has issues if you have a long-running program or if you generate a large number of random numbers -- space issues with a std::vector being one of them.