Generate Random String or Password

Create a random string or password by passing it a string length.

1
2
3
4
5
6
7
8
9
function generateRandomString(length) {
characters = ['2', '3', '4', '5', '6', '7', '8', '9', 'a', 'c', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'm', 'p', 'q', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
randomString = "";
while(randomString.length < length) {
randomCharacterIndex = Math.floor(Math.random()*characters.length);
randomString += characters[randomCharacterIndex];
}
return randomString;
}
Share