import mpmath


def expected_unique(N, k, do_round=True):
    """
    Calculates the expected number of unique values when drawing k from N.

    See https://math.stackexchange.com/questions/72223/finding-expected-number-of-distinct-values-selected-from-a-set-of-integers

    Parameters
    ----------
    N : int
        The population size.
    k : int
        The number of draws.

    Returns
    -------
    float
        The expected number of distinct values.

    """
    n = mpmath.mpf(N)
    p = mpmath.mpf(k)
    temp = mpmath.power((n - 1) / n, p)
    if do_round:
        return max(int(round(n * (1 - temp))), 0)
    else:
        return max(float(n * (1 - temp)), 0)