Skip to content

Instantly share code, notes, and snippets.

@lap00zza lap00zza/idgen.js
Last active Oct 6, 2018

Embed
What would you like to do?
Quick 'n' dirty id generator
const generateId = (len=16) => {
const allowedRanges = [[48, 57], [65,90], [97, 122]];
let str = "";
let expand = allowedRanges.reduce((acc, each) => {
let [start, end] = each;
let nums = [];
for(let i = start; i <= end; i++) {
nums.push(i);
};
return acc.concat(nums);
}, []);
for (let i = 0; i < len; i++) {
str += String.fromCharCode(
expand[Math.floor(Math.random() * expand.length)]
);
}
return str;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.