我住长江头,君住长江尾。日日思君不见君,共饮长江水。 此水几时休,此恨何时已。只愿君心似我心,定不负相思意。
《卜算子·我住长江头》,李之仪
# UUID
# UUID简介
This specification defines a Uniform Resource Name namespace for UUIDs (Universally Unique IDentifier), also known as GUIDs Globally Unique IDentifier). A UUID is 128 bits long, and can guarantee uniqueness across space and time. UUIDs were originally used in the Apollo Network Computing System and later in the Open Software Foundation's (OSF) Distributed Computing Environment (DCE), and then in Microsoft Windows platforms.
# UUID的版本
# Nil UUID
The nil UUID is special form of UUID that is specified to have all 128 bits set to zero.
# UUID1
The time-based version.
# UUID2
DCE Security version, with embedded POSIX UIDs.
# UUID3
The name-based version, uses MD5 hashing.
# UUID4
The randomly or pseudo-randomly generated version.
# UUID5
The name-based version, uses SHA-1 hashing.
以上UUID各版本的解释参考自RFC4122.同时可以参考知乎的回答进行理解:https://www.zhihu.com/question/34876910
# UUID的用法
Python实现了UUID1,UUID3,UUID4,UUID5. UUID库是Python内置的库,无需额外安装,直接使用'import uuid'导入UUID库即可使用。
# Demo
参见github:https://github.com/gaodyun/PythonDemo/tree/master/0001
Demo可以生成一定数目的uuid(UUID3).数目可以由用户自行输入,并且通过正则判断用户的输入是否为0-9的任意数字。代码注释部分是对输入合法性的另一种判断思路:使用异常捕获机制。
# 相关拓展
Snowflake
Twitter: Snowflake https://github.com/twitter/snowflake Snowflake的Python实现: https://github.com/erans/pysnowflake
参考资料: