Can you please take a look at my code and improve it (if necessary)?
Javascript (with jQuery)
function random(min, max) {
return min + parseInt(Math.random() * (max - min + 1), 10);
}
function generatePassword() {
var length = parseInt($('#pwLength').val(), 10),
charset = $('#pwChars').val(),
password = "";
while (length > 0) {
length -= 1;
console.log(length);
password += charset[random(0, charset.length - 1)];
}
return password;
}
function getNewPassword() {
$('#pwResult').html(generatePassword());
}
$(document).ready(function () {
getNewPassword();
$('#getNewPw').click(function () {
getNewPassword();
return false;
});
});
HTML
<ul>
<input type="text" id="pwChars" value="AaBbCcDdEeFfGgHhiJjKkLMmNnoPpQqRrSsTtUuVvWwXxYyZz23456789!?$%#&@+-*=_.,:;()" />
<li><input type="text" id="pwLength" value="10" /></li>
<li><button id="getNewPw">New</button></li>
</ul>
<div id="pwResult" contenteditable="true"></div>