fevangelou
2/16/2016 - 4:28 AM

Generate read-error-free hash. Similar letters absent (like 0 and O).

Generate read-error-free hash. Similar letters absent (like 0 and O).

function randomString(length, chars) {
    var result = '';
    for (var i = length; i > 0; --i) {
        result += chars[Math.round(Math.random() * (chars.length - 1))];
    }
    return result;
}

var dictionary = '';
dictionary+= 'ABCDEFGHKLMNPQRTWXYZ'; // IJOSUV
dictionary+= 'abcdefghkpqrstwxyz'; // ijlmnouv
dictionary+= '2346789'; // 150
dictionary+= '-_~';

alert(randomString(10, dictionary));