I’m using the following JavaScript. The final result is display sequence character.
But I want to display alphanumeric in-sequence order. How do I do that?
var disp = '';
var string = '';
var i;
var chars = "0123456789abcdefghiklmnopqrstuvwxyz";
var ran_unrounded;
var ran_number;
var rnum;
for (i = 0; i < 5; i++) {
rnum = Math.floor(Math.random() * chars.length);
string += chars.substring(rnum, rnum + 1);
ran_unrounded = Math.random() * 3;
ran_number = Math.floor(ran_unrounded);
//document.write(chars.substring(rnum, rnum + 1));
// alert('rnum', rnum, '--', rnum + 1);
disp = chars.substring(rnum, rnum + 8);
}
OK, so from the clarification in the comments above the requirement is to generate a string that contains two random “words”, where each “word” has four characters selected at random from a predefined set of available characters.
Following is one way to do that:
Demo: http://jsfiddle.net/dgnwh/