使用 Python 如何生成 200 个激活码(或者优惠券)

import string, random
#激活码中的字符和数字
field = string.letters + string.digits


#获得四个字母和数字的随机组合
def getRandom():
return “”.join(random.sample(field,4))


# 生成的每个激活码中有几组
def concatenate(group):
return “-“.join([getRandom()
for i in range(group)])


#生成n组激活码
def generate(n):
return [concatenate(4)
for i in range(n)]


if __name__ == ‘__main__’:
print generate(200)

获得结果;

[‘RVpu-mOvh-DeG6-BRNc’, ‘A9kL-HMxY-ML7d-av2n’, ‘FAsK-k34Q-zHiD-u0Hj’, ‘Htjr-afSz-5zUr-jTgb’, ‘Z3V4-fP6F-UVAZ-TK9B’, ‘5Mul-pMda-Qycu-eyLY’, ‘y0CB-Nvsy-l7tv-SwQo’, ‘8Ukv-kKvW-7OvW-Hfqz’, ‘gbt0-LJ6D-GJPA-Fzrb’, ‘D70R-fDL9-yt73-4KIc’]
[Finished in 0.1s]

原文链接:https://blog.csdn.net/a136332462/article/details/53504155?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522165277499316781683913601%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=165277499316781683913601&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~times_rank-10-53504155-null-null.nonecase&utm_term=%E4%BC%98%E6%83%A0

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发
头像
文明发言,共建和谐米科社区
提交
头像

昵称

取消
昵称表情图片