Skip to content

Instantly share code, notes, and snippets.

@alexey-bass
Last active January 5, 2024 00:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexey-bass/6206536 to your computer and use it in GitHub Desktop.
Save alexey-bass/6206536 to your computer and use it in GitHub Desktop.
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));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment