JS生成指定长度的随机数

 /**
* 生成指定长度的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('');
}
上一篇:insert into与insert ignore以及replace into的区别


下一篇:bzoj1070: [SCOI2007]修车(费用流)