import random
import string


def random_string(length=5, length_range=None, capitalized=True, **kwargs):
    """
    Returns a random capitalized string

    If you want to modify the parameters, use a lambda function in your anonymizer like this:
    attributes = [
        ('first_name', lambda **kwargs: replacers.random_string(length_range=(2, 6), **kwargs)),
    ]

    :param length: The wished length of the random string
    :param length_range: Tuple with the wished length range of the random string. ONLY USE length OR length_range!
    :param capitalized: Whether the string should be capitalized
    :return: Random string with the specified params
    """
    if length_range is not None:
        result = "".join(
            random.choice(string.ascii_lowercase)
            for _ in range(random.randrange(*length_range))
        )
    else:
        result = "".join(random.choice(string.ascii_lowercase) for _ in range(length))
    return result.capitalize() if capitalized else result