Skip to content

Instantly share code, notes, and snippets.

@yarkovaleksei
Last active June 22, 2016 13:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yarkovaleksei/7a03a83ab81dc9de706b274412a7de3f to your computer and use it in GitHub Desktop.
Save yarkovaleksei/7a03a83ab81dc9de706b274412a7de3f to your computer and use it in GitHub Desktop.
function _r(maxlength){
maxlength = (maxlength && typeof maxlength === 'number') ? maxlength : 20;
var result = [];
var template = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
template += "abcdefghijklmnopqrstuvwxyz";
template += "0123456789";
template += "`~!@#$%^&*()_+№;:?-=";
while(result.length < maxlength){
var c = template.charAt(Math.floor(Math.random() * template.length));
if(result.indexOf(c) < 0){
result.push(c);
}
}
return result.join('');
}
console.time("random");
for(var i = 0; i < 10000; i++){
console.log(_r());
}
console.timeEnd("random");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment