alphanumeric-random-string-generator
Version:
simple alphanumeric string generator
19 lines (15 loc) • 389 B
JavaScript
const randomString = (num) => {
if (typeof num !== "number") {
return null;
}
if (!Number.isInteger(num)) {
return null;
}
const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
let word = "";
for (let i = 0; i < num; i++) {
word += chars[Math.floor(Math.random() * chars.length)];
}
return word;
};
module.exports = randomString;