js生成UUID
调用方法:可看js说明
Math.uuid(); 常用的
Math.uuidFast(); 这个不用的话可以删了
Math.uuidCompact(); 这个不用的话可以删了
/*! Math.uuid.js (v1.4) http://www.broofa.com mailto:robert@broofa.com Copyright (c) 2010 Robert Kieffer Dual licensed under the MIT and GPL licenses. */ /* * Generate a random uuid. * * USAGE: Math.uuid(length, radix) * length - the desired number of characters * radix - the number of allowable values for each character. * * EXAMPLES: * // No arguments - returns RFC4122, version 4 ID * >>> Math.uuid() * "92329D39-6F5C-4520-ABFC-AAB64544E172" * * // One argument - returns ID of the specified length * >>> Math.uuid(15) // 15 character ID (default base=62) * "VcydxgltxrVZSTV" * * // Two arguments - returns ID of the specified length, and radix. (Radix must be <= 62) * >>> Math.uuid(8, 2) // 8 character ID (base=2) * "01001010" * >>> Math.uuid(8, 10) // 8 character ID (base=10) * "47473046" * >>> Math.uuid(8, 16) // 8 character ID (base=16) * "098F4D35" */ (function() { // Private array of chars to use var CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split(''); Math.uuid = function (len, radix) { var chars = CHARS, uuid = [], i; radix = radix || chars.length; if (len) { // Compact form for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random()*radix]; } else { // rfc4122, version 4 form var r; // rfc4122 requires these characters uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-'; uuid[14] = '4'; // Fill in random data. At i==19 set the high bits of clock sequence as // per rfc4122, sec. 4.1.5 for (i = 0; i < 36; i++) { if (!uuid[i]) { r = 0 | Math.random()*16; uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r]; } } } return uuid.join(''); }; // A more performant, but slightly bulkier, RFC4122v4 solution. We boost performance // by minimizing calls to random() Math.uuidFast = function() { var chars = CHARS, uuid = new Array(36), rnd=0, r; for (var i = 0; i < 36; i++) { if (i==8 || i==13 || i==18 || i==23) { uuid[i] = '-'; } else if (i==14) { uuid[i] = '4'; } else { if (rnd <= 0x02) rnd = 0x2000000 + (Math.random()*0x1000000)|0; r = rnd & 0xf; rnd = rnd >> 4; uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r]; } } return uuid.join(''); }; // A more compact, but less performant, RFC4122v4 solution: Math.uuidCompact = function() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); return v.toString(16); }); }; })();
<html> <head> <title>UUID测试</title> <script src="uuid.js"></script> <script src="jquery-1.7.2.min.js"></script> <script> $(function(){ var begin = new Date(); for(var i=0;i<1000;i++){ //Math.uuid(); //运算1000次,47毫秒 //Math.uuidFast();//运算1000次,31毫秒 //Math.uuidCompact();//运算1000次,78-94毫秒 //$("body").append(Math.uuid()+'<br/>'); $("body").append(Math.uuid()+'<br/>'); } var end = new Date(); alert(end.getTime()-begin.getTime()); //1000个 702毫秒 }); </script> </head> <body> UUID测试<br/> </body>
相关推荐
javascript生成uuid的js库文件
JS生成UUID,网上下的,0分分享,有需要的方便下载
简单快速javascript生成UUID
js生成UUID,使用var myuuid=(new UUID()).id;其中myuuid的值就是需要UUID。
这个函数用最短的代码生成了非常有效的uuid,非常巧妙。短小精悍,一个字符都不多。Returns a random v4 UUID of the form xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx, where each x is replaced with a random ...
javascript 随机生成36为的UUID值
用JS生成UUID的方法实例 <!DOCTYPE html> <html> <head> [removed] [removed] [removed] var id=getUuid(); $(document).ready(function(){ $("p").click(function(){ alert(id); }); })...
主要介绍了两行Javascript代码生成UUID的方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
Math.uuid.js js 生成 uuid
使用第三方模块Underscore.js,Immutable.js,UUID(源代码+截图)使用第三方模块Underscore.js,Immutable.js,UUID(源代码+截图)使用第三方模块Underscore.js,Immutable.js,UUID(源代码+截图)使用第三方模块...
本文实例讲述了JS实现点击生成UUID的方法。分享给大家供大家参考,具体...www.jb51.net 用JS生成UUID的方法实例</title> [removed][removed] [removed] var id = getUuid(); $(document).ready(function() {
UUID.js, 用于JavaScript的符合RFC的UUID生成器 电子邮件名称UUID.js - 适用于JavaScript的兼容UUID生成器概要<!-- HTML5 -->[removed][removed]&
uuid 生成器
A js library to generate and parse UUID's, TimeUUID's and generate empty TimeUUID's based on TimeStamp for ...一个js库,用于生成和解析UUID,TimeUUID,并基于TimeStamp生成空的TimeUUID,以进行范围选择。
@ freeasin / uuid 一个简单的UUID v4生成模块起源该模块基于对的最小字节答案。 该答案已修改为: 受到好评在浏览器和双方的NodeJS运行浏览器打包为ES6模块用法npm install @freeasin/uuid 节点JS const { v4 } = ...
java生成UUID通用唯一识别码.docx
node-uuid, 在JavaScript中,生成符合RFC的uuid uuid 简单。快速生成 RFC4122 uuid 。功能:支持版本 1,4和 5 uuid跨平台使用加密的强随机数 api ( 可用时)零相关性,小容量( 。但不是这个小的 )快速入门- CommonJS...
UUID.js-JavaScript的RFC兼容UUID生成器 概要 <!-- HTML5 --> < script src =" src/uuid.js " > </ script > < script > var uuid = UUID . generate ( ) ; </ script > // Node.js...