I am trying to program a password generator. However, I find that my code is unreliable. I want each run of my function to return 20 random characters. This works most times, however if I spam the function enough times then I sometimes get a result that's below my criteria (eg: 2 strings, none, etc).
var longth = 20, allc = "!@#$%^&*()_+~`|}{[]\:;?><,./-=0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", passgen = ''; for (var i = 0; i < longth; i++) { passgen += allc.charAt(Math.floor(Math.random() * allc.length)); } Not sure if the problem is with logic in my code, or if there's a break in one of the characters in my allc variable that's causing problems. Maybe I'm not expressing the variable correctly.