I'm trying to generate about 6000 random images using python's pillow library. Right now I can't create more than 300 at a time or my program hits the maximum recursion depth. I understand that this is happening because my recursion isn't called with an "n-1" case. Being that all the images are selected using random numbers, I'm not sure how to address this issue. Here is my code:
## Generate Traits
TOTAL_IMAGES = 300 # Number of random unique images we want to generate
all_images = []
# A recursive function to generate unique image combinations
def create_new_image():
new_image = {}
# For each trait category, select a random trait based on the weightings
new_image ["Plant"] = random.choices(plant, plant_weights)[0]
new_image ["Pot"] = random.choices(pot, pot_weights)[0]
new_image ["Face"] = random.choices(face, face_weights)[0]
if new_image in all_images:
return create_new_image()
else:
return new_image
# Generate the unique combinations based on trait weightings
for i in range(TOTAL_IMAGES):
new_trait_image = create_new_image()
all_images.append(new_trait_image)