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

random

作者:互联网

random

import random
random.random()
0.6191685210192187
a=random.randint(1,3)
b=random.randint(1,3)
c=random.randint(1,3)
print(a,b,c)
3 3 1
e=random.choice('hello')
f=random.choice('hello')
g=random.choice('hello')
print(e,f,g)
l e l
seq1=random.sample('hello',2)
seq2=random.sample('hello',2)
seq3=random.sample('hello',2)
print(seq1,seq2,seq3)
['l', 'l'] ['o', 'l'] ['e', 'l']
ls1=[1,2,3,4,5,6]
random.shuffle(ls1)
print(ls1)
[1, 4, 2, 5, 3, 6]

使用用改模块取随机验证码

checkcode=''
for i in range(4):
    current=random.randint(0,9)
    checkcode+=str(current)
print(checkcode,checkcode,checkcode)
7964 7964 7964

标签:checkcode,randint,random,sample,print,hello
来源: https://www.cnblogs.com/yjc-z/p/11750599.html