美文网首页
生成随机字符串

生成随机字符串

作者: 曹锦花 | 来源:发表于2019-08-23 11:01 被阅读0次
export default function (len = 32) {
  const $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
  const maxPos = $chars.length;
  let str = '';
  for (let i = 0; i < len; i++) {
    str += $chars.charAt(Math.floor(Math.random() * maxPos));
  }
  return str;
}

相关文章

网友评论

      本文标题:生成随机字符串

      本文链接:https://www.haomeiwen.com/subject/shwosctx.html