什么是UUID(通用唯一标识符)?

While developing applications or using services or mounting disks in Linux systems we may see the term UUID or 128-bit number which might seem interesting. UUID is a 128-bit number that is used to identify things like name, record, disk whatever we want.

在Linux系统中开发应用程序或使用服务或装入磁盘时,我们可能会看到UUID或128位数字一词,这似乎很有趣。 UUID是一个128位数字,用于标识我们想要的名称,记录,磁盘之类的东西。

UUID的唯一性 (Uniqueness Of UUID)

What makes UUID so special or interesting is its uniqueness. Yes it is right  event two different and discrete systems creates UUID it is assumed both are unique and do not collide each other or with other UUID’s. Actually they are not perfectly unique but the probability of the collusion is very very very low to count.

使UUID如此特别或有趣的是它的独特性。 是的,如果两个不同的离散系统创建UUID是正确的,则假定两者都是唯一的,并且不会彼此冲突或与其他UUID冲突。 实际上,它们并不是完全独特的,但是合谋的可能性却非常低。

示例UUID (Example UUID)

Here are some UUID examples.

这是一些UUID示例。

a8098c1a-f86e-11da-bd1a-00112444be1e

We can see that fstab content of the Linux systems contains UUID in order to identify the disk partition.

我们可以看到Linux系统的fstab内容包含UUID,以便标识磁盘分区。

$ cat /etc/fstab
Example UUID
Example UUID
示例UUID

使用Python生成UUID (Generate UUID with Python)

There are different ways to generate UUID. There is a lot of web-based UUID generators but using Python is more attractive. We can use Python uuid module to generate UUID with different options.

有多种生成UUID的方法。 有很多基于Web的UUID生成器,但使用Python更具吸引力。 我们可以使用Python uuid模块生成具有不同选项的UUID。

生成基于UUID的主机ID (Generate UUID Based Host ID)

While generating UUID we can make some part of UUID bound to the host. We will import uuid module and run uuid1() function in order to generate host-based UUID.

在生成UUID时,我们可以将UUID的一部分绑定到主机。 我们将导入uuid模块并运行uuid1()函数以生成基于主机的UUID。

import uuid 
uuid.uuid1()
Generate UUID Based Host ID
Generate UUID Based Host ID
生成基于UUID的主机ID

生成完全随机的UUID (Generate Fully Random UUID)

If we need to generate completely random UUID we need to call uuid4() function. Every time we call this function will create completely different UUIDs.

如果需要生成完全随机的UUID,则需要调用uuid4()函数。 每次调用此函数时,都会创建完全不同的UUID。

import uuid
uuid.uuid4()
Generate Fully Random UUID
Generate Fully Random UUID
生成完全随机的UUID
LEARN MORE  How To Generate Random Numbers and Password with OpenSSL Rand
了解更多信息如何使用OpenSSL Rand生成随机数和密码

翻译自: https://www.poftut.com/what-is-uuid-universally-unique-identifier/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值