天天看點

js 随機生成指定長度字元

function randomString(n) {  
  let str = 'abcdefghijklmnopqrstuvwxyz9876543210';
  let tmp = '',
      i = 0,
      l = str.length;
  for (i = 0; i < n; i++) {
    tmp += str.charAt(Math.floor(Math.random() * l));
  }
  return tmp;
}      

轉載于:https://www.cnblogs.com/bigman-bugman/p/8953900.html