Created
September 16, 2023 23:38
-
-
Save Nick390/0bbc8a495ebeae2840a1908b660ee56c to your computer and use it in GitHub Desktop.
generate unique id
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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