private int[] randomSelection(Random random, int batchSize) {

      // Random batchSize unique ordered integers of 1024 (VectorizedRowBatch.DEFAULT_SIZE) indices.
      // This could be smarter...
      Set<Integer> selectedSet = new TreeSet<Integer>();
      int currentCount = 0;
      while (true) {
        final int candidateIndex = random.nextInt(VectorizedRowBatch.DEFAULT_SIZE);
        if (!selectedSet.contains(candidateIndex)) {
          selectedSet.add(candidateIndex);
          if (++currentCount == batchSize) {
            Integer[] integerArray = selectedSet.toArray(new Integer[0]);
            int[] result = new int[batchSize];
            for (int i = 0; i < batchSize; i++) {
              result[i] = integerArray[i];
            }
            return result;
          }
        }
      }
    }
Generate random batch source from a random Object[] row source (VectorRandomRowSource).
ql/src/test/org/apache/hadoop/hive/ql/exec/vector/VectorRandomBatchSource.java