Random words, numbers and characters with Javascript
I needed a fast and easy way to generate a couple (5000) of strings containing random characters and I came with the following:
function randStrings(howMany, howLong) {
// define a string with valid characters
var characters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZ"+
"abcdefghiklmnopqrstuvwxyz";
for (var i=0;i<howMany;i++)
{
var word="";
for (var j=0;j<howLong;j++)
{
var rand = Math.floor(Math.random() * characters.length);
word += characters.substring(rand,rand+1);
}
document.writeln(word);
}
}








