Skip to content

Instantly share code, notes, and snippets.

@deyvicode
Last active March 18, 2021 18:07
Show Gist options
  • Save deyvicode/f4d0ad2dcdfffd20e5d92d29928e141e to your computer and use it in GitHub Desktop.
Save deyvicode/f4d0ad2dcdfffd20e5d92d29928e141e to your computer and use it in GitHub Desktop.
generate random characters by lenght number
function makeid(length) {
var result = '';
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var charactersLength = characters.length;
for ( var i = 0; i < length; i++ ) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
console.log(makeid(5));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment