def generate_simulation_intervals(Nd, maxlength, overlap):
    """
    Generate a list of tuples containing the begining
    and the end of any simulation intervals.

    Parameters
    ----------
    Nd : int
        Number of samples from the data set.
    maxlength : int
        Maximum length of simulation intervals.
        The data will be break into intervals of
        this length os smaller.
    overlap : int
        Overlap between two consecutives intervals.

    Returns
    -------
    multiple_shoots : list of tuples
        List of tuples containing the begining
        and the end of simulation intervals.
    """

    Nshoots = Nd // maxlength
    if Nd % maxlength != 0:
        Nshoots += 1

        # Compute actual simulation lenght
        simulation_length \
            = maxlength - \
            (maxlength - Nd % maxlength) // Nshoots

        # Compute a second simulation length and the number of times
        # this diferent length will be applied
        diferent_length = simulation_length-1
        if Nd % simulation_length == 0:
            Nshoots_diferent_length = 0
        else:
            Nshoots_diferent_length \
                = simulation_length - Nd % simulation_length

    else:
        Nshoots_diferent_length = 0
        diferent_length = maxlength
        simulation_length = maxlength

    # Check if diferent_length is large enough
    if diferent_length < overlap:
            raise ValueError("length too small.")

    # Generate list
    multiple_shoots = []
    firstvalue = 0
    for i in range(Nshoots - Nshoots_diferent_length):
        lastvalue = firstvalue+simulation_length + \
                    overlap
        multiple_shoots += [(firstvalue, min(lastvalue, Nd))]
        firstvalue += simulation_length

    for i in range(Nshoots_diferent_length):
        lastvalue = firstvalue + diferent_length + \
                    overlap
        multiple_shoots += [(firstvalue, min(lastvalue, Nd))]
        firstvalue += diferent_length

    return multiple_shoots