import itertools


def create_measurement(sample_period, start_datetime, end_datetime, dist_fct):
    """
    Generate a list of `nsamples` measurements from `start_datetime` (datetime)
    with a `sample_period` (timedelta). The distribution of the measurements is
    set by the generator `dist_fct`
    """
    def date_generator():
        from_date = start_datetime
        while True:
            yield from_date
            from_date = from_date + sample_period

    nsamples = (end_datetime - start_datetime).seconds // sample_period.seconds
    return [(time, dist_fct())
            for time, _ in zip(itertools.islice(date_generator(), nsamples),
                               range(nsamples))]