def renormalize(n, start_range, new_range=[0.5, 1]):
    """
    A function to scale a value from a given range to a new range.

    Apply the function f(x) to n using and old (start_range) and a new range
    where f(x) = (dNewRange / dOldRange * (n - old_range_lower_bound)) + new_lower
    """

    delta1 = start_range[1] - start_range[0]
    delta2 = new_range[1] - new_range[0]

    max_new_range = max(new_range)
    min_new_range = min(new_range)

    if delta1 or delta2:
        try:
            normalized = (delta2 * (n - start_range[0]) / delta1) + new_range[0]
        except ZeroDivisionError:
            normalized = new_range[0]
    else:
        normalized = n

    # The formula results in values slightly smaller and larger than the boundaries of the new range
    if normalized > max_new_range:
        return max_new_range

    elif normalized < min_new_range:
        return min_new_range

    return round(normalized, 4)