I have the following array:
var myArray = [BF1,BA1,BF2, BA2, BF3,BA3, BA4, BF4 , BA5, BF5, BF6, BA6, BF7, BA7, BA8, BF8, BA9, BF9,
BF10, BA10, BA11, BF11, BA12, BF12, BA13, BF13, BA14, BF14, BA15, BF15, BA16, BF16, BF17, BA18,
BF18, BA19, BF19, BA20, BF20, BA21, BF21, BF22, BA22, BA23, BF23, BA24, BF24, BA25, BF25, BA26,
BA27, BF27, BA28, BF28, WA29, WA30, WF30, WA31, WA31, WF32, WA32, WF33, WA33, WF34, WA34,
WF35, WA35, WA36, WA37, WA38, WF38, WA39, WF40, WA40, WA41, WF41, WA42, WF42, WF43, WA43,
WF44, WA44, WF45, WA45, WF46, WF46, WA47, WF47, WA48, WF48, WF49, WA49, WA50, WF50, WF51,
WA51];
I use the following function to shuffle, such that shuffle(myArray);
function shuffle(array){
var counter = array.length,
temp, index;
while (counter > 0){
index = Math.floor(Math.random() * counter);
counter = counter-1;
temp = array[counter];
array[counter] = array[index];
array[index] = temp;
}
return array;
However, I'd like to shuffle with probabilities. Such that items in myArray that begin with B (BF1,BA1,BF2...BF28) have a 0.8 probability of being the first items in the array, and items that begin with W (WA29,WA30,WF30...WA51) have a 0.2 probability of being the first items in the array.
Can I do this using math.random? Or should I use something else?
Thanks in advance!