public void randomTest(Random random, int opCount) {
    cleanState();
    if (DEBUG) {
      log("randomTest");
    }
    final int count = 10; // + nextInt(random,100);
    final int start = nextInt(random, count - 1);
    final int layoutCount = Math.max(1, nextInt(random, count - start));
    setupBasic(count, start, layoutCount);

    while (opCount-- > 0) {
      final int op = nextInt(random, 4);
      switch (op) {
        case 0:
          if (mTestAdapter.mItems.size() > 1) {
            int s = nextInt(random, mTestAdapter.mItems.size() - 1);
            int len = Math.max(1, nextInt(random, mTestAdapter.mItems.size() - s));
            rm(s, len);
          }
          break;
        case 1:
          int s = mTestAdapter.mItems.size() == 0 ? 0 : nextInt(random, mTestAdapter.mItems.size());
          add(s, nextInt(random, 50));
          break;
        case 2:
          if (mTestAdapter.mItems.size() >= 2) {
            int from = nextInt(random, mTestAdapter.mItems.size());
            int to;
            do {
              to = nextInt(random, mTestAdapter.mItems.size());
            } while (to == from);
            mv(from, to);
          }
          break;
        case 3:
          if (mTestAdapter.mItems.size() > 1) {
            s = nextInt(random, mTestAdapter.mItems.size() - 1);
            int len = Math.max(1, nextInt(random, mTestAdapter.mItems.size() - s));
            up(s, len);
          }
          break;
      }
    }
    preProcess();
  }
 @Test
 public void testRandom() throws Throwable {
   mCollectLogs = true;
   Random random = new Random(System.nanoTime());
   for (int i = 0; i < 100; i++) {
     try {
       Log.d(TAG, "running random test " + i);
       randomTest(random, Math.max(40, 10 + nextInt(random, i)));
     } catch (Throwable t) {
       throw new Throwable(
           "failure at random test " + i + "\n" + t.getMessage() + "\n" + mLog.toString(), t);
     }
   }
 }