const randomStr=(n)=>{
var key = []
var smallWord=new Array('z'.charCodeAt()-'a'.charCodeAt()+1).fill().map((item,i)=>{return String.fromCharCode(i+97)});
var bigWord=new Array('Z'.charCodeAt()-'A'.charCodeAt()+1).fill().map((item,i)=>{return String.fromCharCode(i+65)});
var number=new Array(10).fill().map((item,i)=>{return i+''});
var coma=['=','+']
var result='';
key=[...bigWord,...smallWord,...number,...coma];
var keyLen=key.length
for(var i = 0;i<n;i++){
var randomIndex=Math.floor(Math.random()*(keyLen))
console.log(randomIndex)
result+=key[randomIndex]
}
return result
}
复制代码
要注意的地方
'A' 'z'的中间是57个字符除了[A-Z] [a-z]之外还有五个字符 '[' '\' ']' '^' '_' ' ` '