From 599dff39a8ff9435e94a4a341b10dfa9ef7f41e3 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Mon, 27 Aug 2018 01:05:23 +0000 Subject: [PATCH] Switch to random.sample for lore instead of random.choice --- plugins/lore.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/plugins/lore.py b/plugins/lore.py index 8168f1f..1d85938 100644 --- a/plugins/lore.py +++ b/plugins/lore.py @@ -166,13 +166,10 @@ def _lore(channel, count): pins = channel.saved_pins if not pins: return None - if len(pins) < count: - return [_extract_lore(p) for p in pins] - out_lore = set() - while len(out_lore) < count: - random_lore = random.choice(pins) - lore = _extract_lore(random_lore) - out_lore.add(lore) + try: + out_lore = set(_extract_lore(l) for l in random.sample(pins, count)) + except ValueError: + out_lore = [_extract_lore(p) for p in pins] return out_lore def _scribe():