def METHOD_NAME(n_qubits, length):
    """Randomly sample gates and arguments (qubits, angles)"""
    if n_qubits < 3:
        raise ValueError(
            "Please request n_qubits >= 3 so we can use 3-qubit gates."
        )
    gates = list(QUANTUM_GATES.values())
    prog = Program()
    for _ in range(length):
        gate = random.choice(gates)
        possible_qubits = set(range(n_qubits))
        sig = inspect.signature(gate)
        param_vals = []
        for param in sig.parameters:
            if param in [
                "qubit",
                "q1",
                "q2",
                "control",
                "control1",
                "control2",
                "target",
                "target_1",
                "target_2",
                "classical_reg",
            ]:
                param_val = random.choice(list(possible_qubits))
                possible_qubits.remove(param_val)
            elif param == "angle":
                # TODO: support rx(theta)
                if gate == RX:
                    param_val = random.choice([-1, -0.5, 0, 0.5, 1]) * pi
                else:
                    param_val = random.uniform(-2 * pi, 2 * pi)
            else:
                raise ValueError("Unknown gate parameter {}".format(param))
            param_vals.append(param_val)
        prog += gate(*param_vals)
    return prog