ScriptSpot

Forum topic · General Scripting

setting random values based on array

By ce89 · 2014-01-17

Description

I'm trying to assign a random value from a predefined array. For example i have an array and i want to assign a random value from my array to the height of my selected boxes.

myArray = #(10, 20, 30, 40)
for i in selection do
(
i.height = random (myArray)
)
i know this doesn't work but it the best way to show what i am trying to achieve. I only want the new heights to be 10, 20, 30 or 40 as per array values.

Any help would be much appreciated.

Comments (2)

ce89 · 2014-01-18

barigazy,

Thank you for your help, that work's great. It makes complete sense now I see it, but then again it always does afterwards :-)

Thanks again.

barigazy · 2014-01-17


myArray = #(10, 20, 30, 40)
for i in selection do (i.height = myArray[random 1 myArray.count])