Index: trunk/ippTools/src/dettool.c
===================================================================
--- trunk/ippTools/src/dettool.c	(revision 16868)
+++ trunk/ippTools/src/dettool.c	(revision 18088)
@@ -535,4 +535,7 @@
     PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
 
+    PXOPT_LOOKUP_BOOL(randomSubset, config->args, "-random_subset", false);
+    PXOPT_LOOKUP_S32(randomLimit, config->args, "-random_limit", false, false);
+
     PXOPT_LOOKUP_TIME(registered, config->args, "-registered", false, false);
     PXOPT_LOOKUP_TIME(time_begin, config->args, "-time_begin", false, false);
@@ -557,4 +560,6 @@
     PXOPT_COPY_F32(config->args, where, "-select_ccd_temp_min", "ccd_temp", ">=");
     PXOPT_COPY_F32(config->args, where, "-select_ccd_temp_max", "ccd_temp", "<=");
+    PXOPT_COPY_F32(config->args, where, "-select_pon_time_min", "pon_time", ">=");
+    PXOPT_COPY_F32(config->args, where, "-select_pon_time_max", "pon_time", "<=");
     PXOPT_COPY_F32(config->args, where, "-select_posang_min", "posang", ">=");
     PXOPT_COPY_F32(config->args, where, "-select_posang_max", "posang", "<=");
@@ -584,4 +589,23 @@
         psFree(detrendExps);
         return true;
+    }
+
+    if (randomSubset && (randomLimit < detrendExps->n)) {
+      // generate a random-valued vector, return an index sorted by the random values
+      psVector *randomVector = psVectorAlloc(detrendExps->n, PS_TYPE_F32); // random values
+      psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 0);
+      for (int i = 0; i < randomVector->n; i++) {
+        randomVector->data.F32[i] = psRandomUniform(rng);
+      }
+      psVector *indexVector = psVectorSortIndex(NULL, randomVector);
+
+      // accept for first n of the sequence
+      psArray *subset = psArrayAlloc (randomLimit);
+      for (int i = 0; i < randomLimit; i++ ){
+	int j = indexVector->data.S32[i];
+	subset->data[i] = psMemIncrRefCounter (detrendExps->data[j]);
+      }
+      psFree (detrendExps);
+      detrendExps = subset;
     }
 
