Skip to content

Instantly share code, notes, and snippets.

@d0whc3r
Created May 6, 2018 22:28
Show Gist options
  • Save d0whc3r/f28ec0aea946630856099017679ba6f6 to your computer and use it in GitHub Desktop.
Save d0whc3r/f28ec0aea946630856099017679ba6f6 to your computer and use it in GitHub Desktop.
Simple random string
function randString(length = 10) {
// const text = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
// const nums = '0123456789';
// const vals = `${text}${text.toLowerCase()}${nums}`;
const vals = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
return Array(length).fill().map(() => vals.charAt(Math.floor(Math.random() * vals.length))).join('');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment