Return to Snippet

Revision: 54475
at December 28, 2011 22:35 by burnandbass


Updated Code
var sentance:Array = [
								  ["Name 1", "Name 2", "Name 3", "Name 4", "Name 5"],
								  ["and", "without", "and somehow", "and his twin sister"],
								  ["Girl name 1", "Girl name 2", "Girl name 3", "Girl name 4"],
								  ["went ot school", "passed the exams", "went on vacation", "voted for Obama"]
								  ]
			
			var finalString:String = "";
			var separator:String = " ";
			var end:String = ".";
			for(var i:Number = 0; i< sentance.length; i++){
				finalString += String(sentance[i][Number( Math.ceil( Math.random()*sentance[i].length-1 ))] + separator);
			}
						
			finalString = finalString.slice(0, finalString.lastIndexOf(separator)) + end;
			
			trace(finalString);  //output: Name 2 and somehow Girl name 4 voted for Obama.  
//or output: Name 3 and his twin sister Girl name 1 passed the exams.

Revision: 54474
at December 28, 2011 22:33 by burnandbass


Initial Code
var sentance:Array = [
								  ["Name 1", "Name 2", "Name 3", "Name 4", "Name 5"],
								  ["and", "without", "and somehow", "and his twin sister"],
								  ["Girl name 1", "Girl name 2", "Girl name 3", "Girl name 4"],
								  ["went ot school", "passed the exams", "went on vacation", "voted for Obama"]
								  ]
			
			var finalString:String = "";
			var separator:String = " ";
			var end:String = ".";
			for(var i:Number = 0; i< sentance.length; i++){
				finalString += String(sentance[i][Number( Math.ceil( Math.random()*sentance[i].length-1 ))] + separator);
			}
						
			finalString = finalString.slice(0, finalString.lastIndexOf(separator)) + end;
			
			trace(finalString);

Initial URL


Initial Description
This is very simple script, you can add ass meny items and arrays as you want. You can change the separator and/or enging of the sentance. It can be very easily modified to work with external XML files

Initial Title
Simple, but very robust Mad Libs algoritm

Initial Tags


Initial Language
ActionScript 3