void fill_ans()
{
for (int i = 0; i < digit_size; ++i)
ans.push_back( rand() % 9 + 1) ; // a random integer belonging to [1,9]
//for (int i = 0; i < digit_size; ++i)
// cout << ans[i];
}
The program works but sometimes the four digits are not unique. How do I ensure that?
Random numbers and unique numbers are two different things. The easiest way to get unique numbers is to fill a vector with the numbers in the range and shuffle it. Then you can just loop through the vector.