python random模块的一些例子

[root@linux1 python_tidb]# cat mypy02.py
#!/usr/bin/env python3
import pymysql,sys,os,string
import _thread,time,random

print('*'*10)
for i in range(5):
    rand_choice = random.choice(string.ascii_letters)
    print(rand_choice)

print('*'*10)
for i in range(5):
    rand_sample = ''.join(random.sample(string.ascii_letters,5))
    print(rand_sample)

print('*'*10)
for i in range(5):
    rand_num = random.choice(string.digits)
    print(rand_num)

print('*'*10)
for i in range(5):
    rand_int = random.randint(0,100)
    print(rand_int)
[root@linux1 python_tidb]# ./mypy02.py
**********
R
k
i
i
p
**********
Gviuy
wOdLU
aYHSG
CdqbS
YweHm
**********
2
2
3
8
4
**********
81
57
87
74
72

参考了帖子

https://www.runoob.com/python/att-string-join.html

你可能感兴趣的:(python)