def shift_within_range(value, min, max, reverse=False):
    """Shift numeric value within range."""
    values = range(min, max + 1)

    if reverse:
        index = values.index(value) - 1
    else:
        index = values.index(value) + 1

    return values[index % len(values)]