Random Name Generator/Shuffle names with no repeats
Hey everyone,
I'm trying to make a little game where names are chosen randomly from a list and appear on stage each time the user clicks a button. I'm okay with making that happen, but I don't know how to make it so that the same name isn't chosen again. Eventually I'll have a list of about 250 people and I just want each person to be chosen once. I get the concept, but no idea how to make it happen. Can you help?
I'm attaching a zip with the file in it that I'm working with.
Thanks in advance!
var aArray:Array = new Array();
var dummyArray:Array = new Array();
var selectName:String;
var selectNumber:Number;
var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest("200-one-liners.txt"));
myLoader.addEventListener(Event.COMPLETE, aLoaded);
function aLoaded(event:Event):void
{
// *** Change imported data into array;
aArray = event.target.data.split("\r\n");
// *** Get first name and remmove it from imported array;
selectNumber = Math.floor(Math.random() * (aArray.length - 1));
selectName = aArray[selectNumber];
// *** Remove selected from imported array;
aArray.splice(selectNumber,1);
// *** Spit out text value;
status_box.r_status.text = selectName;
}
function clickHandler(event:MouseEvent):void
{
// *** Current button play status;
event.currentTarget.gotoAndPlay("click");
// *** If original array is empty;
if (aArray.length < 1)
{
trace("names empty");
return;
}
else
{
// *** Get next name from array;
selectNumber = Math.floor(Math.random() * (aArray.length - 1));
selectName = aArray[selectNumber];
// *** Push to dummy array;
dummyArray.push(selectName);
// *** Remove next name from original array;
aArray.splice(selectNumber,1);
// *** Spit out text value;
status_box.r_status.text = selectName;
}
// *** Traces;
trace("Dummy Array: " + dummyArray);
trace("Imported Array: " + aArray);
trace("-------------------------");
}