We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
array.choose (Read 378 times)
array.choose
May 9th, 2008, 10:39pm
 
I'm wondering if there's an array.choose method which chooses from among the values of an array?

I keep doing something like

int[] thisArray =  {0,1,1,1,1};

choice=thisArray[in(random(thisArray.length))];


which isn't too bad but it's getting annoying, so I just thought I'd ask.

thanks in advance....



Re: array.choose
Reply #1 - May 10th, 2008, 10:20pm
 
You could write the function yourself:

Code:
int chose(int[] vals)
{
return vals[(int)random(vals.length)];
}


You may have to make a float[] version too...
Re: array.choose
Reply #2 - May 11th, 2008, 9:27pm
 
you're right, I should figure out the syntax for writing classes in processing, thanks for the nudge...
Page Index Toggle Pages: 1