0
How the generated random number with no duplicates
have to make 6 random numbers generate 10 times in 1 run to show there are no duplicates
1 Odpowiedź
+ 1
Have you seen - http://en.cppreference.com/w/cpp/numeric/random ? They've added some new functionality in C++ 11, now you can pick the distribution of the random numbers (uniform_int_distribution in your case I'm guessing).
If you really want there to be no duplicates you can put every generated number in std::set and if your new random number is already in that set - keep regenerating it, until it isn't. Something like this:
static std::set<int> numbersAlreadyGenerated;
int generateNonRepeatingRandomNumber()
{
int randomNumber;
do{
randomNumber = generateRandom();
}while (numbersAlreadyGenerated.find(randomNumber) != numbersAlreadyGenerated.end());
numbersAlreadyGenerated.insert(randomNumber);
return randomNumber;
}