From ae39697add00bbc489066e391b6b8b18371d5de8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E7=BE=85=E7=8B=BC?= Date: Fri, 22 Mar 2024 21:56:24 +0800 Subject: [PATCH] fix --- modules/dice/dice.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/dice/dice.py b/modules/dice/dice.py index 39beb3a5..98d60bf9 100644 --- a/modules/dice/dice.py +++ b/modules/dice/dice.py @@ -1,6 +1,7 @@ -import random -import re import math +import re +import secrets + import numpy as np from config import Config @@ -150,7 +151,7 @@ class Dice(DiceItemBase): output += self.code + ' = ' # 生成随机序列 for i in range(self.count): - dice_results.append(random.randint(1, int(self.type))) + dice_results.append(secrets.randbelow(int(self.type)) + 1) if adv != 0: new_results = [] indexes = np.array(dice_results).argsort() @@ -224,7 +225,7 @@ class FateDice(DiceItemBase): fate_results.extend(['+' for _ in range(2)]) # 从序列中随机选择count个结果 - selected_results = random.sample(fate_results, self.count) + selected_results = [secrets.choice(fate_results) for _ in range(self.count)] output += '[' + ', '.join(selected_results) + ']' # 计算结果