function?random(num)?{
????let?byte_length?=?num?||?32;
????let?chars?=?'';
????for?(let?i?=?0;?i?<?26;?i++)?{
????????chars?+=?String.fromCharCode(65?+?i);
????}
????let?lowerCase?=?chars.toLowerCase();
????let?number?=?'';
????for?(let?i?=?0;?i?<?10;?i++)?{
????????number?+=?i;
????}
????let?allChars?=?chars?+?lowerCase?+?number;
????let?result?=?'';
????for?(let?i?=?0;?i?<?byte_length;?i++)?{
????????result?+=?allChars.charAt(parseInt(Math.random()?*?allChars.length));
????}
????return?result;
}
//?生成64位随机字符串
let?data?=?random(64);
console.log(data);
function?app(data,?count)?{
????let?arr?=?[];
????for?(let?i?=?0,?len?=?data.length?/?count;?i?<?len;?i++)?{
????????let?subStr?=?data.substr(0,?count);
????????arr.push(subStr);
????????data?=?data.replace(subStr,?'');
????}
????let?newStr?=?arr.join('-');
????return?newStr;
}
console.log(app(data,?4));
|