This question already has an answer here:
I have been using this code:
function stringGen()
{
var text = " ";
var charset = "abcdefghijklmnopqrstuvwxyz0123456789";
for( var i=0; i < len; i++ )
text += charset.charAt(Math.floor(Math.random() * charset.length));
return text;
}
But so far, it has not been working, like at all. What am I doing wrong?
Thank you for your help in advance
You missed the parameter
len
.This would give you something like "a1z".
Your len variable is undefined. Either pass it in as a parameter, or set it to something.
http://jsfiddle.net/rg7Z3/
A pretty one-liner would be:
Or if you need a str that is longer than 10/11 characters:
Just as alternative: