/**
* 生成指定长度的UUID
* @param len
* @param radix
* @returns uuid
* eg: createUUID(8, 2) "01001010" createUUID(8, 10) "47473046" createUUID(8, 16) "098F4D35"
*/
调用
var num = createUUID(6, 10);
function createUUID(len, radix) {
var chars = '0123456789'.split('');
var uuid = [], i;
radix = radix || chars.length;
if(len){
for (i = 0; i < len; i++){
uuid[i] = chars[0 | Math.random()*radix];
}
}
return '-'+uuid.join('');
}