Created
November 27, 2014 03:10
-
-
Save anon5r/d2edc78b49ae5ee92e53 to your computer and use it in GitHub Desktop.
Random strings generator
This file contains hidden or 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 randomString(length,numNumeric,numLCase,numUCase,numSymbols){ | |
length=length||16;numNumeric=numNumeric||3,numLCase=numLCase||3,numUCase=numUCase||3,numSymbols=numSymbols||3; | |
var charsList = [ | |
'0123456789', | |
'abcdefghijklmnopqrstuvwxyz', | |
'ABCDEFGHIJKLMNOPQRSTUVWXYZ', | |
'!"#$%&\'()*+,-./\\:;<=>?@[]^_`{|}~' | |
], | |
charLength = [numNumeric,numLCase,numUCase,numSymbols], | |
str="",i=0; | |
while(i<length){ | |
skipchars=true,j=0; | |
while(skipchars&&j<4){ | |
charsType=Math.floor(Math.random()*charsList.length); | |
numCharsCount = charLength[charsType]; | |
if(numCharsCount > 0) skipchars=false; | |
j++; | |
} | |
if(j>=4) | |
charsType=Math.floor(Math.random()*(charsList.length-1)); | |
str+=charsList[charsType][Math.floor(Math.random()*charsList[charsType].length)]; | |
charLength[charsType]--;i++; | |
} | |
return str; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reinvent the wheel.