Skip to content

Instantly share code, notes, and snippets.

@tkh44
Forked from anonymous/randomstring.js
Created December 31, 2012 03:13
Show Gist options
  • Save tkh44/4417143 to your computer and use it in GitHub Desktop.
Save tkh44/4417143 to your computer and use it in GitHub Desktop.
function randomString(length) {
var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz'.split('');
if (! length) {
length = Math.floor(Math.random() * chars.length);
}
var str = '';
for (var i = 0; i < length; i++) {
str += chars[Math.floor(Math.random() * chars.length)];
}
return str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment