1function generatePassword(passwordLength) {
2 var numberChars = "0123456789";
3 var upperChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
4 var lowerChars = "abcdefghijklmnopqrstuvwxyz";
5 var allChars = numberChars + upperChars + lowerChars;
6 var randPasswordArray = Array(passwordLength);
7 randPasswordArray[0] = numberChars;
8 randPasswordArray[1] = upperChars;
9 randPasswordArray[2] = lowerChars;
10 randPasswordArray = randPasswordArray.fill(allChars, 3);
11 return shuffleArray(randPasswordArray.map(function(x) { return x[Math.floor(Math.random() * x.length)] })).join('');
12}
13
14function shuffleArray(array) {
15 for (var i = array.length - 1; i > 0; i--) {
16 var j = Math.floor(Math.random() * (i + 1));
17 var temp = array[i];
18 array[i] = array[j];
19 array[j] = temp;
20 }
21 return array;
22}
23
24alert(generatePassword(12));