public static int getRandomAvailablePort(int protocol, InetAddress addr) {
    while (true) {
      int port =
          rand.nextInt(AVAILABLE_PORTS_UPPER_BOUND - AVAILABLE_PORTS_LOWER_BOUND)
              + AVAILABLE_PORTS_LOWER_BOUND;
      if (isPortAvailable(port, protocol, addr)) {
        return port;
      }
    }
  }
Returns a randomly selected available port in the range 5001 to 32767.

@param protocol The protocol to check (either {@link #SOCKET} or {@link #MULTICAST}).
@param addr the bind-address or mcast address to use
@throws IllegalArgumentException <code>protocol</code> is unknown
geode-membership/src/main/java/org/apache/geode/internal/membership/utils/AvailablePort.java