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()

站长数十年成长感悟,输入暗号查看

桩白墨公众号上还能加入书舟书友群、美团外卖红包群,免费领取站桩和原创 chatgpt 教程哦
暗号:
请关注本站微信公众号,回复“暗号”,即可获取。在微信里搜索“桩白墨”或者“baimoz”或者微信扫描右侧二维码都可以关注站长微信公众号。