def _compute_expected_collisions(keyspace, trials):
    """Compute the expected number of collisions

    Uses formula from Wikipedia:
    https://en.wikipedia.org/wiki/Birthday_problem#Collision_counting

    :param keyspace: keyspace size
    :param trials: number of trials
    :rtype float: Number of expected collisions

    """
    return trials - keyspace + keyspace * ((keyspace - 1) / keyspace) ** trials