function generatePassword(limit, inclNumbers) { var vowels = 'aeiou'.split(''); var constonants = 'bcdfghjklmnpqrstvwxyz'.split(''); var word = '', i, num; if (!limit) limit = 8; for (i = 0; i < (inclNumbers ? limit - 3 : limit); i++) { if (i % 2 == 0) { // even = vowels word += vowels[Math.floor(Math.random() * 4)]; } else { word += constonants[Math.floor(Math.random() * 20)]; } } if (inclNumbers) { num = Math.floor(Math.random() * 99) + ''; if (num.length == 1) num = '00' + num; else if (num.length == 2) num = '0' + num; word += num; } return word.substr(0, limit); }