fixing error in dublicateRandomEntry

This commit is contained in:
Jonas Urban 2025-11-23 17:29:45 +01:00
parent e4a7f9ac28
commit 0a30e04157

View File

@ -13,10 +13,23 @@
static void dublicateRandomEntry (unsigned int *numbers, unsigned int len)
{
unsigned int dubIndx = rand() % len;
unsigned int copyIndx = rand() % len;
if (numbers && len > 2)
{
unsigned int dubIndx = rand() % len;
unsigned int copyIndx;
do {
copyIndx = rand() % len;
} while (copyIndx == dubIndx);
numbers[copyIndx] = numbers[dubIndx];
numbers[len - 1] = numbers[dubIndx];
//switching last entry with random other entry
unsigned int temp;
temp = numbers[copyIndx];
numbers[copyIndx] = numbers[len - 1];
numbers[len - 1] = temp;
}
}
static int compare(const void *a, const void *b)