目標
做為 Apple Store App 獨立開發者,你要搞限時促銷,為你的應用生成激活碼(或者優惠券),使用 Python 如何生成 200 個激活碼(或者優惠券
UUID簡介
UUID是128位的全局唯一標識符,通常由32字節的字符串表示。它可以保證時間和空間的唯一性。
- uuid1:基于時間戳
- uuid2:基于分布式計算環境DCE(python中沒有此函數)
- uuid3:基于名字的MD5散列值
- uuid4:基于隨機數
- 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()