def random_node_presence(t_windows, rep, plac, dur):
    """
    Generate the occurrence and the presence of a node given occurrence_law(occurrence_param)
    and presence_law(presence_param).


    :param t_windows: Time window of the Stream Graph
    :param rep: Number of segmented nodes
    :param plac: Emplacement of each segmented node (sorted array)
    :param dur: Length of each interval corresponding to a segmented node
    :return: node presence
    """
    acc = plac[0] + dur[0]
    if acc > t_windows[1]:
        acc = t_windows[1]
        n_presence = [plac[0], acc]
        return n_presence
    n_presence = [plac[0], acc]
    for i in range(1, rep):
        acc = plac[i] + dur[i]
        if acc > t_windows[1]:
            acc = t_windows[1]
        if acc <= n_presence[-1]:
            continue
        if plac[i] <= n_presence[-1]:
            n_presence[-1] = acc
        else:
            n_presence += [plac[i], acc]
    return n_presence
