I'm making an AS3 program, and in it, when a button (instance name "buy") is clicked, 5 names are randomly picked from a list of about 120 names.
Simple example:
Bob
George
Tom
Mohammed
Adam
Moses
Aaron
David
From these 8 names, it would, for example, randomly pick 3 names.
I also need to make it so that some names are picked more frequently than others. For example, Mohammed will be picked 50% of the time, David 20% of the time, Bob 2% of the time...
How do I do this? I'm pretty new to AS3, and I only know how to do simple things so far.
visit this link to find your solution.
or try this code
var originalArray:Array = new Array('Bob', 'George', 'Tom', 'Mohammed', 'Adam', 'Moses', 'Aaron', 'David');
var shuffledArray:Array = originalArray.sort(shuffle);
trace(shuffledArray);
private function shuffle(originalArray,shuffledArray):int
{
var sortNum : int = Math.round(Math.random() * 2) - 1;
return sortNum;
}