js生成随机车牌号

function getPlate(total = 5) {
    let stateList = '京津冀晋辽吉沪苏浙皖闽琼赣鲁豫鄂湘粤渝川贵云陕甘蒙黑桂藏青宁新'
    let charList = 'ABCDEFGHJKLMNQPRSTUVWXYZ'
    let numList = '1234567890'
    let halfList = [charList, numList]
    let state = dicingChar(stateList)
    let city = dicingChar(charList)
    let sequence = ''
    while (total--) {
        sequence += dicingChar(halfList[Math.round(Math.random())])
    }
    console.log(`${state}${city} ${sequence}`)
}

function dicingChar(series) {
    return series[~~(Math.random() * series.length)]
}

getPlate()

 

posted @ 2021-09-26 18:02  芬尼克斯  阅读(871)  评论(0编辑  收藏  举报