发布于 5年前

js 生成随机字符串

/**
 * @Description: 随机字符串
 * @date 2019/8/7  15:19
 * @param len: 随机字符串长度
 * @param str: 随机字符内容
 */
function randomString (len = 9, 
  str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789') {

  let randomString = ''
  for (let i = 0; i <= len; i++) {
    let randomPoz = Math.floor(Math.random() * str.length)
    randomString += str.substring(randomPoz, randomPoz + 1)
  }
  return randomString
}
©2020 edoou.com   京ICP备16001874号-3