Last active
June 22, 2016 13:03
-
-
Save yarkovaleksei/7a03a83ab81dc9de706b274412a7de3f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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