1 const randomStringMake = (count)=> {
2 const letter = "0123456789ABCDEFGHIJabcdefghijklmnopqrstuvwxyzKLMNOPQRSTUVWXYZ0123456789abcdefghiABCDEFGHIJKLMNOPQRST0123456789jklmnopqrstuvwxyz";
3 let randomString = "";
4 for (let i = 0; i < count; i++) {
5 const randomStringNumber = Math.floor(1 + Math.random() * (letter.length - 1));
6 randomString += letter.substring(randomStringNumber, randomStringNumber + 1);
7 }
8 return randomString
9}
10
11console.log(randomStringMake(10))
1const alpha = 'abcdefghijklmnopqrstuvwxyz';
2const calpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
3const num = '1234567890';
4const specials = ',.!@#$%^&*';
5const options = [alpha, alpha, alpha, calpha, calpha, num, num, specials];
6let opt, choose;
7let pass = "";
8for ( let i = 0; i < 8; i++ ) {
9 opt = Math.floor(Math.random() * options.length);
10 choose = Math.floor(Math.random() * (options[opt].length));
11 pass = pass + options[opt][choose];
12 options.splice(opt, 1);
13}
14console.log(pass);
15
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));