help needed - random function choosing between given values

Hallo everybody,
I am a very beginner in Maxscript. I know how to use random function basically. For example I know how to make a box move randomly on X axis between two values 10 and 30. In this case the box will move randomly on any integer value between 10 and 30. But how to make the box "chose" randomly a position only between the given values 10, 15, 20, 25 and 30? (for example)

Thank you

fra3d

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
fra3d's picture

hallo, using your

hallo,
using your suggestions and making some changes I succeed.
For the system I had to realize (described above) this is the code:

num_arr = #(-1.2, -0.6, 0.0, 0.6, 1.2)
for i in $Box* do
i.pos.y = i.pos.y + num_arr[ random 1 num_arr.count ]

thanks again

fra3d

fra3d's picture

adding to my last post... To

adding to my last post...
To explain more in detail.... I have an array of boxes as panels for an architectural facade model. The boxes of the same row (floor) are slightly placed on two different X axis position every second one, so that every panel doesn't overlap with the next one when moving. The effect I want to obtain with a random function script is not a complete mess in panel positions but a controlled variety of panel positions. This is possible if the panel can choose between three positions, it's initial position, half of it length, and it's total length. Moreover this is the only way to obtain that in some cases two panels have the same Y axis position, and I want this happen in few cases. Actually I would try also with 4 or 5 positions not only 3.

Thanks

fra3d

fra3d's picture

thanks also to

thanks also to Real08121985.
Actually I don't succeed with any of the two suggestions.
Practically I have a Box of Length 2.4m, Width 0.1m and Height 4m. The Length is along the Y axis and I need to make randomly move the Box on the Y axis of 0m (that means it has not to move), 1.2m (half of it's length) or 2.4m (it's total length). Can someone please just write here the necessary lines of script?
Thank you very much

fra3d

real08121985's picture

i think what you want is a

i think what you want is a number from a random index of the array. so you have to create a random index and get the value of the array at that index. note that "num_arr.count" returns the amount of elements in the array.

num_arr = #(10, 15, 20, 25, 30)
arr_ind = random 1 num_arr.count
rand_num = num_arr[ arr_ind ]

fra3d's picture

thank you Anubis. I will

thank you Anubis.
I will try!

fra3d

Anubis's picture

Try with array: num_arr =

Try with array:

num_arr = #(10, 15, 20, 25, 30)
random num_arr[1] num_arr[5]

my recent MAXScripts RSS (archive here)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.