ArrayList<Integer> choosePorts(int count) throws IOException {
    ArrayList<Integer> sockets = new ArrayList<Integer>();
    for (int i = 0; i < count; i++) {
      ServerSocket socket = new ServerSocket(0);
      sockets.add(socket.getLocalPort());
      socket.close();
    }
    return sockets;
  }
Choose a number of random available ports
ambry-network/src/test/java/com/github/ambry/network/SocketServerTest.java