def generate_code(self):
# 定义一个种子,从这里面随机拿出一个值,可以是字母
seeds = "1234567890"
# 定义一个空列表,每次循环,将拿到的值,加入列表
random_num = []
# choice函数:每次从seeds拿一个值,加入列表
for i in range(4):
random_str.append(choice(seeds))
# 将列表里的值,变成四位字符串
return "" . join(random_str)
python生成一个四位数字的随机数
猜你喜欢
转载自blog.csdn.net/qq_33867131/article/details/81018518
今日推荐
周排行