1 function uuid(){ 2 var len=32; //32长度 3 var radix=16; //16进制 4 var chars=‘0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz‘.split(‘‘); 5 var uuid=[],i; 6 radix=radix || chars.length; 7 if(len){ 8 for(i=0;i<len;i++){ 9 uuid[i]=chars[0 | Math.random()*radix]; 10 } 11 }else{ 12 var r; 13 uuid[8]=uuid[13]=uuid[18]=uuid[23]=‘-‘; 14 uuid[14]=‘4‘; 15 for(i=0;i<36;i++){ 16 if(!uuid[i]){ 17 r=0 | Math.random()*16; 18 uuid[i]=chars[(i==19)?(r&0x3)|0x8:r]; 19 } 20 } 21 } 22 return uuid.join(‘‘); 23 }
原文:https://www.cnblogs.com/Charles-Yuan/p/11080023.html