randomizing the seed in multiple copies of an object for noise controller

randomizing the seed in multiple copies of an object for noise controller

avolution
Advocate Advocate
886 Views
3 Replies
Message 1 of 4

randomizing the seed in multiple copies of an object for noise controller

avolution
Advocate
Advocate
Hi!
I want to create a simple animation where the length of a box is controlled
via a noise generator in the trackview. This is easy to do.

Then I want to clone this object as a copy (say 400) and then figure out
a way to have each of the seeds in each of the track view noise generators to
be unique to each other.

This is above my maxscript knowledge.

Is this possible via maxscript?

Thanks
0 Likes
887 Views
3 Replies
Replies (3)
Message 2 of 4

Steve_Curley
Mentor
Mentor
Assuming they are Copies (not instances) then the following should work.

for i in $Box* do (i.length.controller.seed = random 1 400)

Note that the Random function does not guarantee unique values - to make them unique would require looping though those already set to check for duplicates - this would make the code much longer and would slow it down somewhat.. I'll knock one up later for you.

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 3 of 4

Steve_Curley
Mentor
Mentor
You may want to change the value of 400 (in either version) to create more variation in the numbers. I would make it at least twice the number of boxes. If you make it less (than the number of boxes) the script will lock up (not enough available numbers).

(
local rndMax = 400
local seeds = #()
local boxes = $Box*

fn isUniqueSeed index thisSeed =
(
Result = true
for i = 1 to index - 1 do
(
if seeds == thisSeed then
Result = false
)
Result
)

seeds = random 1 rndMax
-- has to be unique, there's only 1 so far

for i = 2 to Boxes.count do
(
rnd = random 1 rndMax
while (not isUniqueSeed i rnd) do
rnd = random 1 rndMax
seeds = rnd
)

for i = 1 to Boxes.count do
Boxes.length.controller.seed = seeds

)

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 4 of 4

avolution
Advocate
Advocate
Thavks very much.
I knew this was way above my humble scripting knowledge.


You may want to change the value of 400 (in either version) to create more variation in the numbers. I would make it at least twice the number of boxes. If you make it less (than the number of boxes) the script will lock up (not enough available numbers).

(
local rndMax = 400
local seeds = #()
local boxes = $Box*

fn isUniqueSeed index thisSeed =
(
Result = true
for i = 1 to index - 1 do
(
if seeds == thisSeed then
Result = false
)
Result
)

seeds = random 1 rndMax
-- has to be unique, there's only 1 so far

for i = 2 to Boxes.count do
(
rnd = random 1 rndMax
while (not isUniqueSeed i rnd) do
rnd = random 1 rndMax
seeds = rnd
)

for i = 1 to Boxes.count do
Boxes.length.controller.seed = seeds

)
0 Likes