Jump to content

Randomizing clones order every n frame with no repetition


Recommended Posts

Hey, so here's my situation:

I have a set of 20 objects

I have a cloner with 4 clones, with all the 20 objects as children (so it shows only 4 at a time)

 

What I need is to get the cloner to show every combination of the 20 obejcts every set number of frames

Thing is, they can't repeat.

 

I know it's like 100k combinations or so, I might not export all of them but I still need to be able to have every frame show a unique different combination, for wtvr amount of frames it takes till every combination runs out.

 

I know it'll probably take some xpresso or python, I just don't know how to approach it.

 

I tried using the "Random" sorting option and changing the seed every frame, but I can already tell some combinations are repeated here and there.

 

Thanks!

Link to comment

Some ideas for you. I used letters as the objects and made a random list on frame 0 (checking for duplications). Makes new set every 10F.

 

Uses a while loop which can be a problem in C4D - if there's any errors it locks up needing a hard reset and you lose all your work. Be cautious when tinkering with the code.

 

cafe rnd5.c4d

 

Link to comment

Dude that's amazing, thank you so much for taking the time!

 

I have two questions if I may,

1. I see that whenever I restart the play, the random process is different. It's actually important in this project for me to have the same random sequence everytime I go back to the project. (I'm going to render the first few thousands, then at a later point have to render the rest, so I have to make sure non of the preivous combinations are repeated)

 

2. In this case, I actually need to have *any* kind of combination so repeating objects in the combination need to exist (1, 1, 1, 1) (1, 2, 2, 2) etc.

Is there an easy way to make *any* combination exist?

 

Thanks again man

Link to comment

Random in Python is based on a seed value (same as C4D). When no seed is specified it is based on system time so is different every run - but you can specify a seed to get repeatable sets of numbers. Insert this in the code

 

def main():
    global lister # persists to next frame
    
    random.seed(100)

    frame = doc.GetTime().GetFrame(doc.GetFps()) # get current frame

 

Can be any number. Don't forget to click compile 😀

 

As for #2 - if you put something like this at the end of the list generation part

 

for c in range(100):
     random.shuffle(lister[c]) # else in order lo - hi
            
lister[20] = [1,1,1,1]

 

it will overwrite the 20th set of numbers with your chosen values. Count starts at 0 . You could have several lines.

 

Let me know if this works.

Link to comment

Dude, thank you so so much. That really is so helpful.

Any chance I could get your contact info? It seems to me like this project is a sort of a tip of an iceberg and I would love to collaborate on upcoming projects if you have the time or will to work on stuff.

Link to comment
×
×
  • Create New...

Copyright Core 4D © 2023 Powered by Invision Community