2fd3461719454015d7ef6be8be27609b3ce22b4c kent Wed Jul 10 13:42:49 2013 -0700 Adding shuffle array of ints. diff --git src/lib/obscure.c src/lib/obscure.c index 99b9681..feaa622 100644 --- src/lib/obscure.c +++ src/lib/obscure.c @@ -603,30 +603,46 @@ /* Shuffle array of characters of given size given number of times. */ { char c; int i, randIx; /* Randomly permute an array using the method from Cormen, et al */ for (i=0; i<arraySize; ++i) { randIx = i + (rand() % (arraySize - i)); c = array[i]; array[i] = array[randIx]; array[randIx] = c; } } +void shuffleArrayOfInts(int *array, int arraySize) +/* Shuffle array of ints of given size given number of times. */ +{ +int c; +int i, randIx; + +/* Randomly permute an array using the method from Cormen, et al */ +for (i=0; i<arraySize; ++i) + { + randIx = i + (rand() % (arraySize - i)); + c = array[i]; + array[i] = array[randIx]; + array[randIx] = c; + } +} + void shuffleArrayOfPointers(void *pointerArray, int arraySize) /* Shuffle array of pointers of given size given number of times. */ { void **array = pointerArray, *pt; int i, randIx; /* Randomly permute an array using the method from Cormen, et al */ for (i=0; i<arraySize; ++i) { randIx = i + (rand() % (arraySize - i)); pt = array[i]; array[i] = array[randIx]; array[randIx] = pt; } }