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;
}

 

posted @ 2018-04-26 17:29  bigman-bugman  阅读(3082)  评论(0编辑  收藏  举报