public int findAvailablePid() throws TimeoutException {
    Stopwatch stopwatch = Stopwatch.createStarted();
    int pid = random();
    while (isProcessAlive(pid)) {
      if (stopwatch.elapsed(MILLISECONDS) > timeoutMillis) {
        throw new TimeoutException(
            "Failed to find available pid within " + timeoutMillis + " millis.");
      }
      pid = random();
    }
    return pid;
  }
Returns randomly unused pid between {@code lowerBound} (inclusive) and {@code upperBound}
(inclusive).
geode-junit/src/main/java/org/apache/geode/internal/process/lang/AvailablePid.java