Skip to content

Instantly share code, notes, and snippets.

@waimyokyaw
Last active July 30, 2019 15:34
Show Gist options
  • Save waimyokyaw/6e5d24a5108633a0592c76148e67c0b9 to your computer and use it in GitHub Desktop.
Save waimyokyaw/6e5d24a5108633a0592c76148e67c0b9 to your computer and use it in GitHub Desktop.
function guid(len) {
var buf = [],
chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
charlen = chars.length,
length = len || 32;
for (var i = 0; i < length; i++) {
buf[i] = chars.charAt(Math.floor(Math.random() * charlen));
}
return buf.join('');
}
console.log(guid());
console.log(guid(15));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment