Skip to content

Instantly share code, notes, and snippets.

@Nick390
Created September 16, 2023 23:38
Show Gist options
  • Save Nick390/0bbc8a495ebeae2840a1908b660ee56c to your computer and use it in GitHub Desktop.
Save Nick390/0bbc8a495ebeae2840a1908b660ee56c to your computer and use it in GitHub Desktop.
generate unique id
function generate_unique_id(length) {
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
let result = '';
for (let i = 0; i < length; i++) {
const randomIndex = Math.floor(Math.random() * characters.length);
result += characters[randomIndex];
}
return result;
}
const uniqueId = generate_unique_id(33);
console.log(uniqueId);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment