import random


def randomLabels(intree, p_speciation=0.7):
    """
    Function to assign random speciation and duplication nodes to a tree. 
    Returns a new tree (leaves the input tree unchanged)

    :param intree: a tree as Dendropy object
    :param p_speciation: probability of a speciation node. 
    """
    t = intree.clone(depth=1)
    for n in t.internal_nodes():
        if random.random() < p_speciation:
            n.label = 'speciation'
        else:
            n.label = 'duplication'
    t.seed_node.label = None
    return(t)