wonderbeyond
11/17/2016 - 3:25 AM

get random string in browser javascript

get random string in browser javascript

function getRandomString(len=8) {
    var res = [];
    const c1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
    const c2 = c1.toLowerCase();
    const choices = c1 + c2 + '0123456789';
    for (var i = 0; i < len; i++) {
        res.push(choices.charAt(Math.floor(Math.random() * choices.length)));
    }
    return res.join('');
}