Hi Steve,

That was actually my first thought. I had a while loop and inside a for ...
in loop to iterate through the array to check if the number was already
there. But then for some reason the script made flash unresponsive.

However  I just came up with this which seems to be working, but i'm still
very curious to learn of better ways of achieving this:

function pickUniqueNumber():Number {

    var randomNum:Number;
    var loop:Boolean = true;

    var numberList:String = "|"+currentNumbers.join("|")+"|";

    while (loop) {

        randomNum = random(wallpaperList.length);

        var numberString:String = "|"+randomNum+"|";

        if (numberList.indexOf(numberString) == -1) {
            currentNumbers.push(randomNum);
            loop = false;
        }
    }
    return randomNum;
}

On Mon, Jul 28, 2008 at 11:04 PM, Steve Abaffy <[EMAIL PROTECTED]>wrote:

> Every time you generate a new random number go through the array and see if
> any match the new number if so generate a new one and check again, if not
> add it to the array.
> With only 10 numbers in the array it would check very fast so you wouldn't
> be taking a performance hit.
>
>
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Eduardo
> Barbosa
> Sent: Monday, July 28, 2008 4:43 PM
> To: Flashcoders mailing list
> Subject: [Flashcoders] Random numbers list
>
> Hi all!
>
> What I am trying to figure out is this:
>
> How to generate a sequence of random numbers where the newest is always
> different from all the previous?
>
> I need to continuosly rewrite an array of 10 random numbers in such a way
> that at any given time they are all different.
>
> Let's say that my range is 0 to 100
>
> it starts with random numbers, all different:
>
> {3, 34, 12, 69, 6, 44, 31, 90, 88, 23}
>
> at a set interval some values are replaced by new ones so there are never
> two equal numbers, so, after 2 seconds it may look like this:
>
> {3, 66, 12, 79, 6, 44, 10, 81, 88, 23}
>
>
> Any ideas?
>
> Thanks :)
> Eduardo
> _______________________________________________
> Flashcoders mailing list
> Flashcoders@chattyfig.figleaf.com
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
>
>
> _______________________________________________
> Flashcoders mailing list
> Flashcoders@chattyfig.figleaf.com
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to