Generate random string

how would one generate a random string text of characters of size NUM, and store these in an array. these must be letters and may contain spacing as well.

You could try this (I suck with strings so this is probably not the best way):

theLetters="abcdefghijklmnopqrstuvwxyz";
function createString (long){
	var tempArray=new Array();
	for (var i=0;i < long;i++){
		tempArray.push(theLetters.charAt(random(theLetters.length-1)));
	}
	return tempArray.join("");
}
// Usage
trace (createString(4));
stringArray=new Array();
for (var j=0;j < 5;j++){
	stringArray.push(createString(8));
}
trace (stringArray);

pom (-:

Im sorry, Im gonna ‘spam’. But I did this in one of the js examples I posted in the random forum. What it was, was a “terms of service” contract people had to go through and supposedly read, though I assumed (and correctly) that they wouldnt and instead would just click through fast without reading at all. After the 5th page or so, the text was completely random - just jumbles of letters and spacings. A friend told me they got to page 33 before realizing what was going on doh! haha it was great.

The code was javascript… actually here it is (man I wrote this years ago too)


// ^ the 4 variables used in the txtlist array were defined above, just body text
var txtlist = [txt1,txt2,txt3,txt4];
var chars = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',' ',' ',' ',' ',' ',' ',' ',' ',' '];
function Cont(){
	if (clicked==0){
		alert("Please choose either:
I accept
or
I do not accept");
	}
	if (clicked==1){
		document.main.accept[0].checked=0;
		document.main.accept[1].checked=0;
		document.main.tos.value = "";
		clicked = 0;
		setTimeout("NextText();",50);
	}
	if (clicked==2){
		location.href="nagware.html";
	}
}

function NextText(){
	if (pos <4){
		document.main.tos.value = txtlist[pos];
		pos++;
	}else{
		randtxt = "(TOS Continued)

" + (pos+1) + ". ";
		for (i=0;i<20;i++){
			number=(35*Math.random())+0.5;
			number=(Math.round(number))-1;
			randtxt = randtxt + chars[number].toUpperCase();
		}
		randtxt = randtxt + "
"
		for (i=0;i<600;i++){
			number=(35*Math.random())+0.5;
			number=(Math.round(number))-1;
			randtxt = randtxt + chars[number];
		}
		document.main.tos.value = randtxt;
		pos++;
	}
}
//-->
</script>

which is more or less AS. :sigh: i used Math.round pffft heh.

pom’s is nice and easy to use though :slight_smile: (mine is the same concept, just not as nice clean heh)

heres the actual implementation of the code above
http://userpages.umbc.edu/~tmccau1/html/twistedaudio/tos.html

the project starts from here
http://userpages.umbc.edu/~tmccau1/html/twistedaudio/

and the tos (terms of service) is actually the first page from that point so you arent missing much starting from there… of course peolpe :seem: to have trouble getting even that far

[spam]

… I was proud of that thing when I made it - it was the first javascripting Ive done so it was an accomplishment for me… I need to revel :slight_smile:

Thats awesome Sen! :slight_smile: People are so stupid…

people… shyeeeah, who needs em?

:slight_smile: thanks Jubba