Skip to content

Instantly share code, notes, and snippets.

@rodrigoalviani
Created September 11, 2023 19:11
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 rodrigoalviani/e8579e3cfc227edabf54a824f7799ffc to your computer and use it in GitHub Desktop.
Save rodrigoalviani/e8579e3cfc227edabf54a824f7799ffc to your computer and use it in GitHub Desktop.
Generate alphanumeric ID
function newid() {
const base = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; // base58
const size = 11;
let id = new Uint8Array(size);
crypto.getRandomValues(id);
let result = "";
for (let i = 0; i < size; i++) {
result += base[id[i] % base.length];
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment