r"""Returns a random unitary gate on K qubits.

    Ref:
        "How to generate random matrices from the classical compact groups"
        Francesco Mezzadri, math-ph/0609050

def random_gate(qubits: Union[int, Qubits]) -> Gate:
    r"""Returns a random unitary gate on K qubits.

    Ref:
        "How to generate random matrices from the classical compact groups"
        Francesco Mezzadri, math-ph/0609050
    """
    N, qubits = qubits_count_tuple(qubits)
    unitary = scipy.stats.unitary_group.rvs(2**N)
    return Gate(unitary, qubits=qubits, name='RAND{}'.format(N))