Skip to content

Instantly share code, notes, and snippets.

@detj
Created December 26, 2013 21:59
Show Gist options
  • Save detj/8139266 to your computer and use it in GitHub Desktop.
Save detj/8139266 to your computer and use it in GitHub Desktop.
Simple function to create API keys consisting of only lower case, upper case alphabets and numbers
function createKey(len) {
var out = [], rand;
len = len || 20;
while(len > 0) {
rand = Math.round(Math.random() * 123);
if ((rand > 47 && rand < 58) || (rand > 64 && rand < 91) || (rand > 96 && rand < 123)) {
out.push(rand);
len--;
}
}
return String.fromCharCode.apply(String, out);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment