wallpaper: compute weights directly

This commit is contained in:
Vincent Bernat 2024-08-12 00:22:15 +02:00
parent f09ba44366
commit c414e90c28

View file

@ -218,8 +218,7 @@ def get_random_images(directory: str, number: int) -> list[Image]:
except (OSError, ValueError): except (OSError, ValueError):
count = 0 count = 0
counts.append(count) counts.append(count)
counts = [(count - min(counts) + 1) ** 3 for count in counts] weights = [100 / ((count - min(counts) + 1) ** 3) for count in counts]
weights = [100 / count for count in counts]
images = [ images = [
PIL.Image.open(image) PIL.Image.open(image)
for image in random.choices(image_files, k=number, weights=weights) for image in random.choices(image_files, k=number, weights=weights)