42ew222 发表于 2016-3-15 09:27:21

python 生成随机优惠码(随机字符串)

第 0001 题:做为 Apple Store App 独立开发者,你要搞限时促销,为你的应用生成激活码(或者优惠券),使用 Python 如何生成 200 个激活码(或者优惠券)?
https://github.com/Yixiaohan/show-me-the-code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import random

codeLength = 12
codeCount = 200
codeOrig = "ABCDEFGHIJKLMNOPQRST1234567890"

def makePromoteCode(count):
    for i in range(count):
      promotecode = ""
      for x in xrange(codeLength):
            promotecode += random.choice(codeOrig)
      print promotecode
         
if __name__ == '__main__':
    makePromoteCode(codeCount)






页: [1]
查看完整版本: python 生成随机优惠码(随机字符串)