Move items randomly without repeating consecutively

Hi guys,

I would like your help.

I have 3 different curves on the same plane. I need to move them on z axis. Then I need to select them in a way they dont repeat, they need to be random. On the right I did it by hand. I figured out a way but its repeating at least twice like the second image.

What would be the best way?

Thanks



3 curves.3dm (86.8 KB)

This one is pretty easy.

Start by creating a list of your curves. Then create an array of planes in the desired direction. Then orient your curves to the array of planes by creating a list of random indexes, which has a domain equal to the number of curves in your list.

Hope this helps.


Random Distribution.gh (9.6 KB)

Thanks for your feedback.

But did you notice the one you did, the square shape repeat twice in a row.
I need them to be sorted randomly but cant repeat. has to be something like this 0,1,2,1,2,0,1,2,1,0ā€¦
and not like this. 0,1,1,2,1,1,0,2,1,2,2,0ā€¦ (notice there are numbers repeating twiceā€¦)
Thanks

Hello
you could apply the 4 color theorem to your problem.

The tool need a Topology that links a slice to the other
Slice 0 is linked to 1
Slice 1 is linked to 0 and 2
ā€¦
Then the tool could propose you color (index) that are not the same.

n color.gh (9.3 KB)

Thank you!

Will give it try on this one, looks very interesting. I used colors just be visual, at the end I wont need the colors. But looks like I can extract the list I am looking for.

Thanks

Sure! Easy and no plug-ins required!

I realized I made an error in my original script. The domain for indexes need to have an upper limit of (ListLength - 1). I have adjusted this here.

If you do not want repeating indexes, and since we are working with a one dimension array, you can increase the length of the index set, then delete consecutive indexes in the set. Finally split the list to obtain the correct amount of indexes from the lengthened list.


Random Distribution.gh (14.8 KB)

1 Like

Indeed there are no colors, just indexes (integer here).

The advantage to this approach is it will always be truly ā€œrandomā€ (pseudo-random anyway), and the randomization can be adjusted by changing the seed.

Iā€™m not exactly sure how the plug-in @laurent_delrieu suggested works, but it appears to be more algorithmic than random (meaning you will always get the same order of indexes).

This uses Jitter for randomness but itā€™s very difficult to find a ā€˜Seedā€™ that never repeats. Maybe an Anemone loop would work? Or maybe the premise is misguided?


randomly_2024_Jul23a.gh (10.7 KB)

1 Like

Hello @baileydw
you are right this simple approach doesnā€™t need plugin. The ā€œn colorā€ method has the advantage to be be more generic has it uses topology.
The tool I made also use the same random (.NET random) and there is 2 modes, one that limit the number of colors (2 here) or another like your approach (the one I propose).
It is funny that you could see

on so little numbers. Probability could be tricky ! I tested the 2 tools with 1000 and 10000 elements and I get this count for 0, 1 and 2.
Your result is on the left.
image


n color.gh (19.7 KB)
it seems you have too much 2. So your better tool could have a flaw somewhere !

And also donā€™t forget that you could use random Integers
image

Yet your code requires Nautilus. :frowning: :man_facepalming:

Yes and no as the tool is freely available on the link I provide.

And you wanted to use Anemone, so you can keep your useless comment to yourself. Anemone is a plugin. And please help us to find the flaw in @baileydw script that could explain why there are not an equal number of items

@laurent_delrieu while I appreciate the attention to detail regarding the ā€œnot equal number of itemsā€, this constraint was not originally proposed by OP, so I had not included it in the script. Good call on the random integer option, I had forgot about that! No need to roundā€¦ Finally, I only assumed the solution you posted was algorithmic and not random because there is no seed slider, but there appears is an ā€˜Sā€™ input on the component you showed, which I assume is the seed input? I just cant be bothered to install another plug-in when itā€™s not needed.

@Joseph_Oster why use Jitter when the script I uploaded already solves the issue of culling repeating consecutive indexes? No need to ā€˜fit a square peg into a round holeā€™ so to speak.

Yes you are totally right, no need of plugin for this but it is useful to know the ā€œn colorā€ theorem that could be useful in many architecture problems (panels ā€¦).

Also I think I understood why there are more 1 than 0 and 2, as you use round
it is better to set an interval like [-0.4999 to 2.4999] in order to have an equal number of 0,1 and 2


If you donā€™t do that you have 25 % of 0, 50 % of 1 and 25 % of 2.

And for the integer option of Random it is not good and I donā€™t know why

2 Likes

Thats amazing.
Made even better.

Indeed the n color will also be very useful for faƧade panel in my workflow!

Thanks guys!

2 Likes

Ouch! Yes, Anemone is a plugin I use from time to time.

I missed that detail, will look again.

Here is a solution that uses Anemone, with colors not limited to 3, but as I type this, I realize the color count should match the number of curves. Oh, well Iā€™m outta here, donā€™t like to hang where Iā€™m not wanted.

Except for one showing ā€œ0 to 300ā€ (seed range), these text panels can be ignored.


randomly_2024_Jul23b.gh (26.2 KB)

1 Like

I looked but still donā€™t see it? OH! DCon. Thatā€™s a new one to me, cool. 100 in, 63 out.

1 Like

It is new to me too! Unfortunately it has some serious limitationsā€¦

I wish it output the values of the culled items, instead of just the countā€¦ This would be highly useful when trying to replace the removed items to the end of the list as, I am attempting to do here.

Maybe you can help me determine how to re-insert the removed consecutive items to the end of the list?


Random Distribution.gh (20.8 KB)

Sorry, Iā€™m done here, but I donā€™t have any idea how to do what you ask.

I used your polygon idea and connected the number of colors to it:


randomly_2024_Jul23c.gh (24.7 KB)

P.S. Replace color generator (yellow group) with new Palette cluster.

randomly_2024_Jul23d.gh (31.0 KB)

2 Likes