def gini(distances):
    """Calculate an approximation of the Gini coefficient for a set of values.

    The Gini coefficient represents the evenness of a set of values, and is in
    the range [0,1], where 0 is perfectly even and 1 is perfectly uneven.

    In practice, this means that sets with low Gini coefficients have more even
    binding frequencies and are more likely to not favor highly-repeated regions
    or other aberrations in the target genome.

    :param distances: a vector of primer binding distances (from each other)
    """
    distances.sort()
    height = area = 0
    for value in distances:
        height += value
        area += height - value / 2.0
    fair_area = height * len(distances) / 2
    return (fair_area - area) / fair_area
