前端js生成任意随机数

// n位随机数生成
function randomNum(n) {
    let sString = "";
    let strings = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    for (i = 0; i < n; i++) {
        ind = Math.floor(Math.random() * strings.length);
        sString += strings.charAt(ind);
    }
    return sString
}

用法:
randomNum(16)

  

posted @ 2021-08-17 17:16  lucky_tomato  阅读(892)  评论(0编辑  收藏  举报