import random


def choose_in_available_edges(available_edges, n=None):
    """
    Randomly choose an edge among available edges (ie not already existing)
    :param n: A node to be in the edge
    :param available_edges: The dictionary of available_edges for each node {
    node: list of constraints}
    :return: the chosen edge as a couplt (variable node, constraint node)
    """
    if not available_edges:
        return (None, None)
    if n is not None:
        node = n
        c = random.choice(available_edges[n])
    else:
        node, available_constraints = random.choice(list(available_edges.items()))
        c = random.choice(available_constraints)

    return (node, c)