golangbot
golangbot
发布于 2周前

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
}