UNPKG

@marcho4917/randomid-generator

Version:

This application allows you to generate a random ID from an available sequence of characters. The length of the random ID depends on the length that the user gives.

11 lines (10 loc) 356 B
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;