Maciek thanks for clearing that up, but in this case the array being access
was created with known values.  so no possibility of sparsity.

On Mon, Mar 3, 2008 at 10:27 AM, Maciek Sakrejda <[EMAIL PROTECTED]>
wrote:

>   Note that this will break on sparse arrays, though. In Flex, it's
> perfectly valid to have something like
>
> var foo:Array = [];
> foo[0] = 2;
> foo[3] = 5;
>
> This array has length 4, but only two elements. Elements 1 and 2
> evaluate to 'undefined'. I'm not sure if there's an easy way to pick a
> random element out of a sparse array. If you want something
> unscientific, I suppose you can just increment the randomly chosen index
> until you find something. Or randomly pick again (although with *really*
> sparse arrays, this could theoretically be a perf problem).
> --
> Maciek Sakrejda
> Truviso, Inc.
> http://www.truviso.com
>
>
> -----Original Message-----
> From: Sean Scott <[EMAIL PROTECTED] <sean.net%40gmail.com>>
> Reply-To: flexcoders@yahoogroups.com <flexcoders%40yahoogroups.com>
> To: flexcoders@yahoogroups.com <flexcoders%40yahoogroups.com>
> Subject: Re: [flexcoders] Newbie Question - Random position in an array
> Date: Sat, 1 Mar 2008 22:55:49 -0600
>
> Sherif,
>
> Thanks i ended up with var randSeed:Number = new
> Number(Math.floor(Math.random() * this.techniColors.length));
>
> On Sat, Mar 1, 2008 at 9:48 PM, Sherif Abdou <[EMAIL 
> PROTECTED]<sherif626%40yahoo.com>
> >
> wrote:
> something like this should work
>
> var randomNumber:int = Math.Random * myArray.length;
>
> then do something like myArray[randomNumber] whatever
>
>
>
>
> ----- Original Message ----
> From: Sean Scott <[EMAIL PROTECTED] <sean.net%40gmail.com>>
> To: flexcoders@yahoogroups.com <flexcoders%40yahoogroups.com>
> Sent: Saturday, March 1, 2008 9:39:39 PM
> Subject: [flexcoders] Newbie Question - Random position in an
> array
>
> Hi folks, wondering if someone has a function that returns a
> random position from an array.
>
> Thanks from a newbie,
>
>
>
>
>
>
>
> __________________________________________________________
> Never miss a thing. Make Yahoo your homepage.
>
>  
>

Reply via email to