风尚云网前端-js随机生成自定义位随机字符

 风尚云网前端-js随机生成自定义位随机字符

废话不多说: 上代码

// 随机生成随机数
    randomPassword(size) {
      var seed = new Array(
        "A",
        "B",
        "C",
        "D",
        "E",
        "F",
        "G",
        "H",
        "I",
        "J",
        "K",
        "L",
        "M",
        "N",
        "P",
        "Q",
        "R",
        "S",
        "T",
        "U",
        "V",
        "W",
        "X",
        "Y",
        "Z",
        "a",
        "b",
        "c",
        "d",
        "e",
        "f",
        "g",
        "h",
        "i",
        "j",
        "k",
        "m",
        "n",
        "p",
        "Q",
        "r",
        "s",
        "t",
        "u",
        "v",
        "w",
        "x",
        "y",
        "z",
        "2",
        "3",
        "4",
        "5",
        "6",
        "7",
        "8",
        "9"
      ); //数组
      var seedlength = seed.length; //数组长度
      let createPassword = "";
      for (let i = 0; i < size; i++) {
        let j = Math.floor(Math.random() * seedlength);
        createPassword += seed[j];
      }
      console.log("随机组合:", createPassword);
    },

有什么不懂的欢迎使用下方评论

猜你喜欢

转载自blog.csdn.net/zsx0806/article/details/125405334