From 0b3485a90e38a40cc059cfbd55d52a7676c78c6a Mon Sep 17 00:00:00 2001 From: xtaodada Date: Fri, 9 Sep 2022 19:08:53 +0800 Subject: [PATCH] =?UTF-8?q?lottery=20=E4=BF=AE=E5=A4=8D=E5=BC=80=E5=A5=96?= =?UTF-8?q?=E4=BA=BA=E6=95=B0=E5=B0=91=E4=BA=8E=E9=A2=84=E5=AE=9A=E4=BA=BA?= =?UTF-8?q?=E6=95=B0=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lottery/main.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lottery/main.py b/lottery/main.py index 452752a..41cdb61 100644 --- a/lottery/main.py +++ b/lottery/main.py @@ -32,10 +32,13 @@ async def lottery_end(): all_user = lottery_bot.get_subs()[:lottery_json["num"]] secret_generator = secrets.SystemRandom() win_user = [] - for _ in range(min(lottery_json["win"], len(all_user))): + win_user_num = min(lottery_json["win"], len(all_user)) + while True: temp = secret_generator.choice(all_user) if temp not in win_user: win_user.append(temp) + if len(win_user) >= win_user_num: + break win_text = end_text.format( lottery_json["title"], "\n".join(f"@{uid}" for uid in win_user