wallpaper: avoid underflow when computing weights

This commit is contained in:
Vincent Bernat 2024-08-03 17:58:48 +02:00
parent 4924483665
commit 9d9b95b201

View file

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