random模块
import random
1. random()
print(random.random())
2. randint(m,n)
print(random.randint(1,3))
3. randrange(start,stop,step)
print(random.randrange(1,3))
4. choice()/choices()
print(random.choice([1,'aaa',[1,2]]))
for i in range(10):
print(random.choices('123',weight=(100,10,1)))
5. sample([...],n)
print(random.sample([1,'aaa',[1,2]],2))
6. uniform(m,n)
print(random.uniform(1,3))
7. shuffle
lst=[1,3,5,7,9]
random.shuffle(lst)
print(lst)
print(ord('A'),ord('Z'))
print(ord('a'),ord('z'))
print(chr(65),chr(90))
print(chr(97),chr(122))
res=''
random_lst = [str(i) for i in range(10)]
for i in range(65,91):
random_lst.append(chr(i))
for i in range(97,123):
random_lst.append(chr(i))
for i in range(6):
res += random.choice(random_lst)
print(res)
import random
import string
print(string.ascii_lowercase)
print(string.ascii_uppercase)
print(string.digits)
print(''.join(random.sample(string.ascii_lowercase + string.ascii_uppercase + string.digits,6)))