[英]Python RANDOM always got same result
I have this code ⬇️ in a Telegram bot (whit telebot).我在 Telegram 机器人(whit telebot)中有这个代码⬇️。 When I send /start it send a random element but It send always the same
当我发送 /start 时,它会发送一个随机元素,但它总是发送相同的
v1 = "1111"
v2 = "ABCD"
v3 = "EFGH"
v4 = "XXXX"
v5 = "0000"
list = [v1, v2, v3, v4, v5]
abcd = random.choice(list)
@bot.message_handler(commands=['help', 'start'])
def send_welcome(message):
bot.reply_to(message, abcd)
How can I solve it?我该如何解决?
You select a value only once.你 select 一个值只有一次。 Replace
bot.reply_to(message, abcd)
with bot.reply_to(message, random.choice(list))
to get random result every time.将
bot.reply_to(message, abcd)
替换为bot.reply_to(message, random.choice(list))
每次都得到随机结果。
You could use你可以使用
@bot.message_handler(commands=['help', 'start'])
def send_welcome(message):
bot.reply_to(message, random.choice(['1', '2', '3', '4']))
I think it is better to use a smaller amount of variables and the variable name list
is a built-in class also check if you have a random.seed()
in your code我认为最好使用较少数量的变量,变量名称
list
是内置的 class 还检查代码中是否有random.seed()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.