在python中是否已经生成了包含仅使用数字的强随机序列的包?

 手机用户2602918637 发布于 2023-01-11 07:53

我在python中使用uuid包生成随机代码,但它使用数字和字符.在python中是否已经生成了包含仅使用数字的强随机序列的包?(目前我有两个选项来生成序列(36位),方法是通过调用random()或将字符转换为数字来生成每个数字,但如果这是足够随机的话,我不会这样做.

1 个回答
  • Python返回的uuid实际上是一个类,因此您可以轻松地以不同的格式获取它:

    >>> import uuid
    >>> uuid.uuid4().int
    27168693431722041803402778536822837233
    

    这是UUID类型的在线帮助.你想要这个int属性.

    >>> help(uuid.UUID)
    Help on class UUID in module uuid:
    
    class UUID(builtins.object)
     |  Instances of the UUID class represent UUIDs as specified in RFC 4122.
     |  UUID objects are immutable, hashable, and usable as dictionary keys.
     |  Converting a UUID to a string with str() yields something in the form
     |  '12345678-1234-1234-1234-123456789abc'.  The UUID constructor accepts
     |  five possible forms: a similar string of hexadecimal digits, or a tuple
     |  of six integer fields (with 32-bit, 16-bit, 16-bit, 8-bit, 8-bit, and
     |  48-bit values respectively) as an argument named 'fields', or a string
     |  of 16 bytes (with all the integer fields in big-endian order) as an
     |  argument named 'bytes', or a string of 16 bytes (with the first three
     |  fields in little-endian order) as an argument named 'bytes_le', or a
     |  single 128-bit integer as an argument named 'int'.
     |  
     |  UUIDs have these read-only attributes:
     |  
     |      bytes       the UUID as a 16-byte string (containing the six
     |                  integer fields in big-endian byte order)
     |  
     |      bytes_le    the UUID as a 16-byte string (with time_low, time_mid,
     |                  and time_hi_version in little-endian byte order)
     |  
     |      fields      a tuple of the six integer fields of the UUID,
     |                  which are also available as six individual attributes
     |                  and two derived attributes:
     |  
     |          time_low                the first 32 bits of the UUID
     |          time_mid                the next 16 bits of the UUID
     |          time_hi_version         the next 16 bits of the UUID
     |          clock_seq_hi_variant    the next 8 bits of the UUID
     |          clock_seq_low           the next 8 bits of the UUID
     |          node                    the last 48 bits of the UUID
     |  
     |          time                    the 60-bit timestamp
     |          clock_seq               the 14-bit sequence number
     |  
     |      hex         the UUID as a 32-character hexadecimal string
     |  
     |      int         the UUID as a 128-bit integer
     |  
     |      urn         the UUID as a URN as specified in RFC 4122
     |  
     |      variant     the UUID variant (one of the constants RESERVED_NCS,
     |                  RFC_4122, RESERVED_MICROSOFT, or RESERVED_FUTURE)
     |  
     |      version     the UUID version number (1 through 5, meaningful only
     |                  when the variant is RFC_4122)
     |  
    

    2023-01-11 08:02 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有