python基础 随机数生成 发表于 2023-05-17 更新于 2025-06-10 分类于 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 randomrandom.sample(["0","1","2","3","4","5","6","7","8","9"],8) 随机数字+字母: 使用random sample: import randomrandom.sample("".join("0123456789qazwsxedcrfvtgbyhnujmikolpQAZWSXEDCRFVTGBYHNUJIKOLP"), 8)