博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Javascript生成UUID(方法2)
阅读量:4710 次
发布时间:2019-06-10

本文共 2191 字,大约阅读时间需要 7 分钟。

 

 

可以先直接在线生成一个uuid,预览一下,

这个网站不错,可以选择uuid version,还可以直接去掉中划线,好用的不得了啊,哈哈

 

//On creation of a UUID object, set it's initial valuefunction UUID(){    this.id = this.createUUID();}// When asked what this Object is, lie and return it's valueUUID.prototype.valueOf = function(){ return this.id; };UUID.prototype.toString = function(){ return this.id; };//// INSTANCE SPECIFIC METHODS//UUID.prototype.createUUID = function(){    //    // Loose interpretation of the specification DCE 1.1: Remote Procedure Call    // since JavaScript doesn't allow access to internal systems, the last 48 bits    // of the node section is made up using a series of random numbers (6 octets long).    //     var dg = new Date(1582, 10, 15, 0, 0, 0, 0);    var dc = new Date();    var t = dc.getTime() - dg.getTime();    var tl = UUID.getIntegerBits(t,0,31);    var tm = UUID.getIntegerBits(t,32,47);    var thv = UUID.getIntegerBits(t,48,59) + '1'; // version 1, security version is 2    var csar = UUID.getIntegerBits(UUID.rand(4095),0,7);    var csl = UUID.getIntegerBits(UUID.rand(4095),0,7);    // since detection of anything about the machine/browser is far to buggy,    // include some more random numbers here    // if NIC or an IP can be obtained reliably, that should be put in    // here instead.    var n = UUID.getIntegerBits(UUID.rand(8191),0,7) +            UUID.getIntegerBits(UUID.rand(8191),8,15) +            UUID.getIntegerBits(UUID.rand(8191),0,7) +            UUID.getIntegerBits(UUID.rand(8191),8,15) +            UUID.getIntegerBits(UUID.rand(8191),0,15); // this last number is two octets long    return tl + tm  + thv  + csar + csl + n;};//Pull out only certain bits from a very large integer, used to get the time//code information for the first part of a UUID. Will return zero's if there//aren't enough bits to shift where it needs to.UUID.getIntegerBits = function(val,start,end){    var base16 = UUID.returnBase(val,16);    var quadArray = new Array();    var quadString = '';    var i = 0;    for(i=0;i
<= aUUID.rand = function(max){ return Math.floor(Math.random() * (max + 1));};

调用方法:UUID.prototype.createUUID()

转载于:https://www.cnblogs.com/freemancheung/p/5485017.html

你可能感兴趣的文章
游戏开发中常用的设计模式
查看>>
Linux 中/etc/profile、~/.bash_profile 环境变量配置及执行过程
查看>>
JAVA:图形之利用FontMetrics类居中
查看>>
使用rsync同步目录
查看>>
[读码时间] for循环遍历设置所有DIV块元素背景色为红色
查看>>
网页调用迅雷下载文件
查看>>
Python 调用 Shell命令
查看>>
POJ 1159 Palindrome(最长公共子序列)
查看>>
责任链模式(chain of responsibility)
查看>>
[转载]java多线程学习-java.util.concurrent详解(一) Latch/Barrier
查看>>
ionic - 运行起来
查看>>
Shell 输入/输出重定向
查看>>
数据结构与算法分析(C++)读书笔记
查看>>
(转)nginx应用总结(1)--基础认识和应用参数优化配置
查看>>
(转)关于sql和MySQL的语句执行顺序(必看!!!)
查看>>
UVALive 3668 A Funny Stone Game(博弈)
查看>>
信息论随笔2: 交叉熵、相对熵
查看>>
再学习之MyBatis.
查看>>
CodeWars题目筛选
查看>>
MySQL— 索引
查看>>