import socket


def _get_available_ports(n: int) -> list[int]:
    """
    Get available ports.

    Parameters
    ----------
    n : int
        number of ports to get.

    Returns
    -------
    list[int]
        Available ports.
    """
    socks: list[socket.socket] = [socket.socket() for _ in range(n)]
    list(map(lambda sock: sock.bind(("", 0)), socks))
    ports: list[int] = [int(sock.getsockname()[1]) for sock in socks]
    for sock in socks:
        sock.close()
    return ports