@ms-kodi-2024/randomid-generator
Version:
The module is used to generate a random string of characters that can be used to obtain unique identifiers.
11 lines (10 loc) • 342 B
JavaScript
const randomID = (idLength) => {
let id = '';
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const charsAmount = characters.length;
for(let i = 0; i < idLength; i++) {
id += characters.charAt(Math.floor(Math.random() * charsAmount));
}
return id;
}
module.exports = randomID;