lundi 21 septembre 2015

How to get random generated Numbers with no Repeat

Hey everyone I have seen some forums about this but can't seem to figure it out still.

So I have an Array called aClockArray and this is a custom array which has 4 Movie clips inside of it. The nested Movie clips have a different color for each frame. I have the array set up like so in my constructor:

aClockArray = [playScreen.wire_5, playScreen.wire_6, playScreen.wire_7, playScreen.wire_8];

Then in another Function I have a for loop setup to iterate through all objects in array and have them gotoAndStop on a random Frame in their Nested Movie clip it goes from 2-7 that I have it randomize like so:

private function randomColorGenerator():void 
    {
        //Loop through wires and make them randomn generate color
        for (var i:int = 0; i < aClockArray.length; i++)
        {
           var currentWires = aClockArray[i];

           nWire = randomNumber(2, 7);

           currentWires.gotoAndStop(nWire);


        }
    }

Now this works perfect and I get random colors every time I restart. But What I would like to accomplish is for the colors not to repeat so not to have the nWire = randomNumber(2, 7); 2-7 numbers repeat. How would I go about doing this to have these numbers random generate and not repeat?

Also Here is my randomNumber function:

//Generates a truly "random" number
    function randomNumber(low:Number=0, high:Number=1):Number
    {
      return Math.floor(Math.random() * (1+high-low)) + low;
    }

Thank you any help would be appreciated!




Aucun commentaire:

Enregistrer un commentaire