0%

python基础 随机数生成

python基础 随机数生成:


使用zfill填充生成:

str(random.randint(0,99999999)).zfill(8)

使用string生成:

import string

"".join(map(lambda x:random.choice(string.digits), range(8)))

使用random sample:

import random
random.sample(["0","1","2","3","4","5","6","7","8","9"],8)




随机数字+字母:

使用random sample:

import random
random.sample("".join("0123456789qazwsxedcrfvtgbyhnujmikolpQAZWSXEDCRFVTGBYHNUJIKOLP"), 8)