zoukankan      html  css  js  c++  java
  • Lua生成Guid(uuid)

      全局唯一标识符(GUIDGlobally Unique Identifier)也称作 UUID(Universally Unique IDentifier) GUID是一种由算法生成的二进制长度为128位的数字标识符。GUID主要用于在拥有多个节点、多台计算机的网络或系统中。在理想情况下,任何计算机和计算机集群都不会生成两个相同的GUIDGUID 的总数达到了2^1283.4×10^38)个,所以随机生成两个相同GUID的可能性非常小,但并不为0GUID一词有时也专指微软对UUID标准的实现。
    在理想情况下,任何计算机计算机集群都不会生成两个相同的GUID随机生成两个相同GUID的可能性是非常小的,但并不为0。所以,用于生成GUID的算法通常都加入了非随机的参数(如时间),以保证这种重复的情况不会发生。
     Windows 平台上,GUID 广泛应用于微软的产品中,用于标识如注册表项、类及接口标识、数据库、系统目录等对象。
    function guid()
        local seed={'e','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'}
        local tb={}
        for i=1,32 do
            table.insert(tb,seed[math.random(1,16)])
        end
        local sid=table.concat(tb)
        return string.format('%s-%s-%s-%s-%s',
            string.sub(sid,1,8),
            string.sub(sid,9,12),
            string.sub(sid,13,16),
            string.sub(sid,17,20),
            string.sub(sid,21,32)
        )
    end
    
    local s=0
    local start_time=os.clock()
    while s<50000 do
        s=s+1
        print(s,guid())
    end
    print('execute_time='..tostring(os.clock()-start_time))
  • 相关阅读:
    IOS开发——01_第一个OC程序
    01_iOS开发需要准备什么?
    正则表达式随笔
    .net4.6版本前设置window子窗口位置主窗口闪烁
    [CF1486D] Max Median
    [CF1487D] Pythagorean Triples
    [CF1487E] Cheap Dinner
    [CF1490E] Accidental Victory
    [CF1490F] Equalize the Array
    [CF1490G] Old Floppy Drive
  • 原文地址:https://www.cnblogs.com/tpfOfBlog/p/8125327.html
Copyright © 2011-2022 走看看