def pulse_train(time, start, duration, repeat_time, end):
    """
    Implements vensim's PULSE TRAIN function.

    Parameters
    ----------
    time: function
        Function that returns the current time.
    start: float
        Starting time of the pulse.
    duration: float
        Duration of the pulse.
    repeat_time: float
        Time interval of the pulse repetition.
    end: float
        Final time of the pulse.

    Returns
    -------
    float:
        - In range [-inf, start):
            returns 0
        - In range [start + n*repeat_time, start + n*repeat_time + duration):
            returns 1
        - In range [start + n*repeat_time + duration,
                    start + (n+1)*repeat_time):
            returns 0

    """
    t = time()
    if start <= t < end:
        return 1 if (t - start) % repeat_time < duration else 0
    else:
        return 0