目標(biāo)
做為 Apple Store App 獨(dú)立開發(fā)者,你要搞限時(shí)促銷,為你的應(yīng)用生成激活碼(或者優(yōu)惠券),使用 Python 如何生成 200 個(gè)激活碼(或者優(yōu)惠券
UUID簡介
UUID是128位的全局唯一標(biāo)識符,通常由32字節(jié)的字符串表示。它可以保證時(shí)間和空間的唯一性。
- uuid1:基于時(shí)間戳
- uuid2:基于分布式計(jì)算環(huán)境DCE(python中沒有此函數(shù))
- uuid3:基于名字的MD5散列值
- uuid4:基于隨機(jī)數(shù)
- uuid5:基于名字的SHA-1散列值
代碼
import uuid
def generateCode(num):
list = []
for i in range(num):
list.append(uuid.uuid1())
return list
if __name__ == "__main__":
codes = generateCode(20000)
code_file = open('gencodes.txt', 'w')
for code in codes:
code_file.write(str(code) + "\n")
code_file.close()