import random
import string


def device_name_list(min_devices=0, max_devices=10, unique=False):
    """
    Return a function that returns a random list of device names based on
    parameters.

    :param int min_devices: the minimum number of device names to generate
    :param int max_devices: the maximum number of device names to generate
    :param bool unique: ensure that all device names are unique
    """

    def the_func():
        return [
            "/dev/%s"
            % "".join(
                random.choice(string.ascii_uppercase + string.digits) for _ in range(4)
            )
            for _ in range(random.randrange(min_devices, max_devices + 1))
        ]

    if unique:

        def the_unique_func():
            devices = set()
            while len(devices) < min_devices:
                for device in the_func():
                    devices.add(device)

            return list(devices)

        return the_unique_func

    return the_func