def correct(sampling, targetsize):
    """this corrects entries in sampling so that entries go from 0 to targetsize-1, and removes duplicates"""
    ratio = float(max(sampling)) / targetsize
    newsamp = []
    for i, s in enumerate(sampling):
        val = min(int(round(s / ratio)), targetsize - 1)
        while val in newsamp:
            print(val)
            val = val - 1
            if val < 0:
                raise Exception('run failed, please rerun')
        newsamp.append(val)
    return newsamp
