src/lib/obscure.c 1.47
1.47 2009/07/22 17:36:22 markd
changed shuffleArrayOfPointer to produce a truly uniform random permutation of the input elements (from stanford)
Index: src/lib/obscure.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/lib/obscure.c,v
retrieving revision 1.46
retrieving revision 1.47
diff -b -B -U 4 -r1.46 -r1.47
--- src/lib/obscure.c 18 Sep 2008 20:02:45 -0000 1.46
+++ src/lib/obscure.c 22 Jul 2009 17:36:22 -0000 1.47
@@ -566,11 +566,12 @@
{
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 = rand() % arraySize;
+ randIx = i + (rand() % (arraySize - i));
pt = array[i];
array[i] = array[randIx];
array[randIx] = pt;
}