Random password generator with JavaScript


In JavaScript To generate password use the following function.

function generatePW()
{
var i=0;
var s="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_?/:(){}[]0123456789";
var pw="";
var c=(Math.random() * 3)+9;
for (i=0; i<c; i++)
{
pw+=s.charAt(Math.random() * 72);
}
return(pw);}

Here the JavaScript function Math.random() generates a random number from 0 to 1 (actually just less than 1). So the code:
var c=(Math.random() * 3)+9; will generate a number between 9 to just less than 12.

Leave a comment