其他分享
首页 > 其他分享> > random

random

作者:互联网

import random
# print(random.random())
# print(random.randint(1,8))
# print(random.choice(['123','eee',[1,2,3]]))
# print(random.shuffle)
# print(random.sample(['123',4,[1,2]],2))
# print(random.randrange(1,4))

#验证码函数
def v_code():
code = ' '
for i in range(5):
#if i == random.randint(0,2):
j = random.randrange(0,2)
if j == 0:
b = random.randrange(10)
else:
b = chr(random.randrange(65,91))
code+=str(b)
print(code)

v_code()

#print(chr(97)) 将97变成对应的ascII码表中的字符

def v_code2():
code = ''
for i in range(5):
add = random.choice([random.randrange(10),chr(random.randrange(65,91))])
code += str(add)
print(code)
v_code2()

标签:code,randrange,random,chr,65,print
来源: https://www.cnblogs.com/styleonme/p/11157308.html