2017年11月2日

Python 练习册 => 0001 生成 200 个激活码

使用uuid模块生成随机数。随机uuid的重复几率极小,可忽略,适合作为激活码。这里使用uuid4()。

详见维基百科

以下为uuid模块说明(help(uuid))

This module provides immutable UUID objects (class UUID) and the functions uuid1(), uuid3(), uuid4(), uuid5() for generating version 1, 3, 4, and 5 UUIDs as specified in RFC 4122.

If all you want is a unique ID, you should probably call uuid1() or uuid4(). Note that uuid1() may compromise privacy since it creates a UUID containing the computer’s network address. uuid4() creates a random UUID.

代码如下:

#!/usr/bin/env python
# encoding: utf-8
import uuid

def main():
    for i in range(200):
        print(uuid.uuid4())

if __name__ == "__main__":
    main()

“以书为舟,遨游尘世”,
最好的免费 kindle 电子书分享站:

You may also like...

发表回复

您的电子邮箱地址不会被公开。


*