fixing error in dublicateRandomEntry
This commit is contained in:
parent
e4a7f9ac28
commit
0a30e04157
@ -13,10 +13,23 @@
|
|||||||
|
|
||||||
static void dublicateRandomEntry (unsigned int *numbers, unsigned int len)
|
static void dublicateRandomEntry (unsigned int *numbers, unsigned int len)
|
||||||
{
|
{
|
||||||
unsigned int dubIndx = rand() % len;
|
if (numbers && len > 2)
|
||||||
unsigned int copyIndx = rand() % len;
|
{
|
||||||
|
unsigned int dubIndx = rand() % len;
|
||||||
|
unsigned int copyIndx;
|
||||||
|
|
||||||
numbers[copyIndx] = numbers[dubIndx];
|
do {
|
||||||
|
copyIndx = rand() % len;
|
||||||
|
} while (copyIndx == 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)
|
static int compare(const void *a, const void *b)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user