Random Array without Sequential Repeats
Hi,
Continuing to build the eLearning exercise (much help from kglad). Ran into a problem with sequential repeats in the random array, needing a solution. The AS3 script (much help here from kglad) to generate and then shuffle the array, often (since there are only 9 potential elements for an array length of 70) produces sequential repeats. For example, using 1,2,3,4,5,6,7,8,9 as elements, the shuffled final array can produce 2,2,2,1,4,5,9,3,3.......
Problem is that when these repeats are used in textbox.text, there is no transition between same (repeated) "words." If a word changes (for example from 5 to 3), the user sees a visiable change. However, with these repeats (for example, 3 to 3), there is no transition: the repeat appears to just stay the same for a longer time. Then the user isn't sure if they've already chosen this word.
In any event, it would be better, since I can't seem to add a visible transition for repeats, to simply avoid sequential repeats, if possible. But cannot figure out a way to add this to the script.
Any help appreciated.
The current random array and shuffle scripts:
var index:int = 0;
var numToDisplay:int = 10;
var groupA:Array = ["1","2","3"]
var groupB:Array = ["4","5","6"]
var groupC:Array = ["7","8","9"]
var word_array:Array = [];
var i:int;
for(i=0;i<3;i++){
word_array.push(groupA[Math.floor(groupA.length*Math.random())]);
}
for(i=0;i<3;i++){
word_array.push(groupB[Math.floor(groupB.length*Math.random())]);
}
for(i=0;i<3;i++){
word_array.push(groupC[Math.floor(groupC.length*Math.random())]);
}
shuffle(word_array);
function shuffle(a:Array) {
var i:int;
var j:int;
var e:*;
var len:int = a.length;
for (i = len-1; i>=0; i--) {
j=Math.floor((i+1)*Math.random());
e = a;
a = a
; a
= e; }
}
