import random


def assign_random_coordinates(node_tuple_list, max_x_coordinate, max_y_coordinate):
    """
    @param node_tuple_list a list with entries of the form (v, x, y) or (v),
           where v is a node number and x,y are coordinates, if present
    @return a modified node_tuple_list in which tuples with no coordinates
            are replaced by random ones in the ranges
            [1,max_x_coordinate] or [1,max_y_coordinate], respectively;
            if a max coordinate is 0, the range is based on the other coordinate;
            if both are 0, the range is [0.0, 1.0]
    """
    if max_x_coordinate == 0:
        max_x_coordinate = max_y_coordinate
    if max_y_coordinate == 0:
        max_y_coordinate = max_x_coordinate
    # if both were 0 originally, they will continue to be 0
    new_node_tuple_list = []
    for node_tuple in node_tuple_list:
        v = node_tuple[0]
        if len(node_tuple) == 3:
            x = node_tuple[1]
            y = node_tuple[2]
        else:
            if max_x_coordinate == 0:
                x = random.uniform(0, 1)
            else:
                x = random.randint(1, max_x_coordinate)
            if max_y_coordinate == 0:
                y = random.uniform(0, 1)
            else:
                y = random.randint(1, max_y_coordinate)
        new_node_tuple_list.append((v, x, y))
    return new_node_tuple_list