b2a2dc48de94edbae86b7f1d2f73f909b85e0740 kent Sat Apr 13 17:49:38 2013 -0700 Adding shuffleArrayOfChars library function. diff --git src/lib/obscure.c src/lib/obscure.c index 09f00b6..b1b60bc 100644 --- src/lib/obscure.c +++ src/lib/obscure.c @@ -575,30 +575,46 @@ char *greek[] = {"B", "KB", "MB", "GB", "TB", "PB"}; int i = 0; long long d = 1; while ((size/d) >= 1024) { ++i; d *= 1024; } double result = ((double)size)/d; if (result < 10) safef(s,slength,"%3.1f %s",((double)size)/d, greek[i]); else safef(s,slength,"%3.0f %s",((double)size)/d, greek[i]); } +void shuffleArrayOfChars(char *array, int arraySize, int shuffleCount) +/* 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 shuffleArrayOfPointers(void *pointerArray, int arraySize, int shuffleCount) /* 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; }