Copy link to clipboard
Copied
I am trying to create a randomizing function that returns the contents of an array once in a random order. I have the following array:
var randomArray:Array=["one","two","three"]
and I have the following code inside the function:
var r:int=Math.floor(Math.random()*randomArray.length);
trace(randomArray.splice(r,1));
It traces the array once through randomly, but stops when it gets to the end of the array. I suppose that is due to the splice command. What do I need to do to have the function constantly call a new random ordering, instead of stopping once it runs through the first trace?
Copy link to clipboard
Copied
I don't see how that does what you say you want it to do (returns the contents of an array in random order)... it is not randomizing the order of the array. It is removing things from it.
What do you have that continually calls the functions or that calls for retracing within the function?