热线电话:13121318867

登录
2019-03-17 阅读量: 461
python如何生成4位数字OTP?

python如何生成4位数字OTP

代码:

# import library

import math, random

# function to generate OTP

def generateOTP() :

# Declare a digits variable

# which stores all digits

digits = "0123456789"

OTP = ""

# length of password can be chaged

# by changing value in range

for i in range(4) :

OTP += digits[math.floor(random.random() * 10)]

return OTP

# Driver code

if __name__ == "__main__" :

print("OTP of 4 digits:", generateOTP())

输出:

OTP of 4 digits: 3211
0.0000
4
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子