Random choice from 4 values

Moderators: Disciple, zlovatt

Post Reply
vjair
Posts: 3
Joined: June 23rd, 2008, 9:18 am

hello :)

ok, what id like to do is set an expression for rotation, so that the amount is determined from a selection of four - 0,90,180,270

if i can make each random choice occur at an equaly spaced amount of time it would be great, but its not essential.

thanks :)

Arran.
User avatar
lloydalvarez
Enhancement master
Posts: 460
Joined: June 17th, 2004, 9:27 am
Location: New York City, NY
Contact:

Code: Select all

fps=5;  //interval of change in frames per second
choices = [0,90,180,270];  // enter the values to choose from, you can add more values as long as they are separated by comma

posterizeTime(fps);
r=Math.round(random (0,choices.length-1));
choices[r]

-Lloyd
vjair
Posts: 3
Joined: June 23rd, 2008, 9:18 am

thanks very much for such a quick reply, that did exactly what i wanted :D

i had a feeling it needed an array ( right term ? ) but couldnt get it to work... at last i know i was looking along the right area though :)


Arran.
User avatar
lloydalvarez
Enhancement master
Posts: 460
Joined: June 17th, 2004, 9:27 am
Location: New York City, NY
Contact:

This is one of those problems that you can actually solve many different ways, but I think this is an efficient and scalable (ie, you can add more values and the expression won't break) solution.
And yes, that's an array :D

-Lloyd
Post Reply