I made a linked sorted list type, and I'm trying to insert unique random integers into it. I tried using the following method to keep the integers unique, but when I try it, I'm still getting duplicate integers. Is there something I'm missing with this method?
Code:
int generate_numbers(const int min, const int max)
{
LinkedSortedList<int> list;
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> dis(min, max);
list.insertSorted(dis(gen));
return dis(gen);
}
void InsertRandomInts()
{
LinkedSortedList<int> list;
LinkedSortedList<int> copyOfList(list);
srand((unsigned)time(NULL));
for (int i = 0; i < 50; ++i)
{
int b = generate_numbers(1, 100);
list.insertSorted(b);
if (b % 2)
{
copyOfList.insertSorted(b);
list.removeSorted(b);
}
}
Comment