import random


def generate_targets(alp, stim_number):
    """Generate a list of targets for each trial, minimizing duplication."""
    if (stim_number <= len(alp)):
        return random.sample(alp, stim_number)

    # minimize duplicates
    times, remainder = divmod(stim_number, len(alp))

    lists = [random.sample(alp, len(alp)) for _ in range(times)]
    lists.append(random.sample(alp, remainder))

    # flatten list of lists
    targets = [target for sublist in lists for target in sublist]

    return targets