uuid.js
// On creation of a UUID object, set it's initial value
function UUID(){
this.id = this.createUUID();
}
// When asked what this Object is, lie and return it's value
UUID.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<base16.length;i++){
quadArray.push(base16.substring(i,i+1));
}
for(i=Math.floor(start/4);i<=Math.floor(end/4);i++){
if(!quadArray[i] || quadArray[i] == '') quadString += '0';
else quadString += quadArray[i];
}
return quadString;
};
//Replaced from the original function to leverage the built in methods in
//JavaScript. Thanks to Robert Kieffer for pointing this one out
UUID.returnBase = function(number, base){
return (number).toString(base).toUpperCase();
};
//pick a random number within a range of numbers
//int b rand(int a); where 0 <= b <= a
UUID.rand = function(max){
return Math.floor(Math.random() * (max + 1));
};
uuid.js的更多相关文章
- UUID(uuid)js 生成
全局唯一标识符(GUID,Globally Unique Identifier)也称作 UUID(Universally Unique IDentifier) . GUID是一种由算法生成的二进制长度 ...
- jquery生成UUID的方法
来源: http://www.broofa.com/2008/09/javascript-uuid-function/ 1.代码: http://www.broofa.com/Tools/Math ...
- javascript 生成UUID
代码一: /*! Math.uuid.js (v1.4) http://www.broofa.com mailto:robert@broofa.com Copyright (c) 2010 Rober ...
- Node.js开发指南中的例子(mysql版)
工作原因需要用到nodejs,于是找到了<node.js开发指南>这本书来看看,作者BYVoid 为清华大学计算机系的高材生,年纪竟比我还小一两岁,中华地广物博真是人才辈出,佩服. 言归正 ...
- 简单了解uuid
1.含义 UUID-Universally Unique IDentifiers,翻译过来就是“全局唯一标志符”. UUID到底是什么? UUID是一个标帜你系统中的存储设备的字符串,其目的是帮助使用 ...
- 关于UUID
UUID是通用唯一识别码的缩写,其目的,是让分布式系统中的所有元素,都能有唯一的辨识信息. UUID是指在一台机器上生成的数字,它保证对在同一时空中的所有机器都是唯一的. 在做后台管理的时候,经常会碰 ...
- 兼容amd,commonjs和browser的模块写法
从uuid.js中抽出来的写法. (function() { var _global = this; // Export public API var obj = {}; obj.attr = fun ...
- ligerui grid行编辑示例
<%@ page contentType="text/html; charset=UTF-8" %> <% String path = request.getCo ...
- javascript常用插件
Math.uuid.js 功能:js 版生成uuid 地址:http://www.broofa.com/ jquery.waterfall.js 功能:瀑布布局图片 地址:https://github ...
随机推荐
- android widgets控件
1.TextView 类似,C#里的lable,显示一段文本 <TextView android:id="@+id/textView2" android:layout_wid ...
- 单片机C51串口发送、接收寄存器
所以,发送和接收寄存器可使用同一地址,编写验证程序(发送和接收是独立空间):读取一个数(1)->发送一个数(2)->再读取得1则是独立空间 不知道STM32串口寄存器和C51串口寄存器是否 ...
- C语言里字符串的解析
根据给定的字符串,按照一定规则解析字符串,卡住好几次,这次做个笔记,以供参考 函数名称: strtok 函数原型: char *strtok(char *s1, const char *s ...
- CF 558B(Amr and The Large Array-计数)
B. Amr and The Large Array time limit per test 1 second memory limit per test 256 megabytes input st ...
- HDU 2009 整除的尾数 题解
Problem Description 一个整数,仅仅知道前几位,不知道末二位.被还有一个整数除尽了.那么该数的末二位该是什么呢? Input 输入数据有若干组,每组数据包括二个整数a,b(0&l ...
- MRP Force Reservation的作用
生产单根据BOM计算出相应的物料需求,生产领料单stock.picking ( internal moves) Stock.picking使用工作流自动计算库存量,如果库存量够,则使用 test_as ...
- 关于IP地址与MAC地址(网卡硬件地址)的区别小谈
IP地址是指Internet协议使用的地址,而MAC地址是Ethernet协议使用的地址. IP地址与MAC地址之间并没有什么必然的联系,MAC地址是Ethernet NIC(网卡)上带的地址,为48 ...
- SQL基础-->层次化查询(START BY ... CONNECT BY PRIOR)
--====================================================== --SQL基础-->层次化查询(START BY ... CONNECT BY ...
- location.href用法总结
javascript中的location.href有很多种用法,主要如下. self.location.href=”/url” 当前页面打开URL页面 location.href=”/url” 当前页 ...
- JAVA WEB学习笔记(三):简单的基于Tomcat的Web页面
注意:每次对Tomcat配置文件进行修改后,必须重启Tomcat 在E盘的DATA文件夹中创建TomcatDemo文件夹,并将Tomcat安装路径下的webapps/ROOT中的WEB-INF文件夹复 ...