Archived
1
0
Fork 0
This commit is contained in:
多羅狼 2024-03-22 21:56:24 +08:00 committed by GitHub
parent cd6c83f521
commit ae39697add
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,6 +1,7 @@
import random
import re
import math import math
import re
import secrets
import numpy as np import numpy as np
from config import Config from config import Config
@ -150,7 +151,7 @@ class Dice(DiceItemBase):
output += self.code + ' = ' output += self.code + ' = '
# 生成随机序列 # 生成随机序列
for i in range(self.count): 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: if adv != 0:
new_results = [] new_results = []
indexes = np.array(dice_results).argsort() indexes = np.array(dice_results).argsort()
@ -224,7 +225,7 @@ class FateDice(DiceItemBase):
fate_results.extend(['+' for _ in range(2)]) fate_results.extend(['+' for _ in range(2)])
# 从序列中随机选择count个结果 # 从序列中随机选择count个结果
selected_results = random.sample(fate_results, self.count) selected_results = [secrets.choice(fate_results) for _ in range(self.count)]
output += '[' + ', '.join(selected_results) + ']' output += '[' + ', '.join(selected_results) + ']'
# 计算结果 # 计算结果