python - 如何在给定范围内在python中生成UUID

标签 python mysql uuid

我需要为 MYSQL intBigInt 生成 UUID,它需要在给定范围 中,我需要 10 位数字 我已为其编写代码的整数 UUID

def getUniqueID():
    unique_id = uuid4().int & (0 << 32) - 1
    return unique_id

例如,SQL int 不应超过 2147483647 的限制。(unique_id < 2147483647)。

def getUniqueID(min,max):

    unique_id = uuid4().int & (0 << 32) - 1
    return unique_id

此处发现 SQL int 限制,

https://dev.mysql.com/doc/refman/8.0/en/integer-types.html

最佳答案

首先你可以安装shortuuid:

python -m pip install shortuuid

然后你可以像这样使用它:

import shortuuid
print(shortuuid.ShortUUID().random(length=10))

项目在github: https://github.com/skorokithakis/shortuuid

关于python - 如何在给定范围内在python中生成UUID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58839091/

相关文章:

mysql - MySQL Char() 或其他字段的顺序 UID 集生成

python - 对我的数组中的随机数进行排序

php - 使用 Doctrine_RawSql 对象连接 3 个表

java - 在 Java 中将字符串 UUID 转换为 BigInteger

mysql - MySQL中的UUID性能?

mysql - 对于 SQL 查询,使用 where 子句错误计数

python - 在 Linux 上的 Python 中,如何获取 socket.gethostbyaddr 以返回 Windows 机器的 netbios 名称

python - 使用 ElementTree 获取 XML 元素时遇到问题

python - Matomo 以前的 Piwik API.getBulkRequest 返回空列表

php - 在 jQuery AJAX 表单提交上使用数据库查询更新表