Hi all,

Im trying to create random panels, so im using lunchbox package which works great, now my question is how to randomize those panels with specific sizes (Minimum - Maximum)…Thanks in advance.

Hi all,

Im trying to create random panels, so im using lunchbox package which works great, now my question is how to randomize those panels with specific sizes (Minimum - Maximum)…Thanks in advance.

I think this is a much more complicated problem than it appears, depending on what you’re actually trying to achieve. You will most likely have to do the divisions yourself rather than using Lunchbox. You can use the U and V measurements at each end (parameter 0 and 1) of the surface along with a desired number of divisions to determine whether using that will make you exceed one of your limits. For example, if your surface is 100 by 100 units, and you want a maximum panel width of 10 units, dividing your surface by any less than 10 will make you exceed that limit. So, if you were to divide the surface 5 times, each panel would have a width of 20 units. This is complicated enough for panels of equal sizes, however you will run into additional challenges with randomization. You need to ensure that the difference between each of the division points does not exceed your established bounds.

Given a curve measuring 100 units long, dividing it at parameters `[0.1, 0.2, 0.3...0.9]`

will divide it into lengths of 10 units. Let’s say your minimum allowable length is 5 and your maximum allowable length is 15. If you modify each of these parameters by a random factor, you might end up with the final parameter being 0.98. This would make the last panel 2 units long, which is below the allowable minimum. You then might think to remove this point, but in doing so, you may be left with the final parameter being 0.83. This makes your last panel 17 units long, which is above the allowable maximum.

This isn’t impossible to do with Dynamo, but I would recommend using Python to calculate the random division points. You can set up a `while`

loop which keeps track of the remaining length in the curve and appropriately accounts for the placement of the last division point to avoid dividing the curve where you are not supposed to. Here’s an example in Python for calculating these parameters:

```
import random
v0 = 0 # V curve minimum value
v1 = 100 # V curve maximum value (length)
normalize = 1.0/v1
div_min = 10.0 # Or IN[0]
div_max = 20.0 # Or IN[1]
# Normalize desired panel sizes to corresponding curve parameter
div_min_norm = div_min*normalize
div_max_norm = div_max*normalize
div_points = []
current = 0
while True:
param = random.uniform(div_min_norm, div_max_norm)
current += param
# Exit loop if current location exceeds min limit
if 1-current < div_min_norm:
break
div_points.append(current)
OUT = div_points
```

You’ll probably want to use seeds to ensure that you get identical results for the same curve between executions. Here’s the output for 3 separate executions:

`[0.17501733850523293, 0.2867550690259471, 0.47790955510480776, 0.6614252756011072, 0.8240699398438589]`

`[0.1483432681515528, 0.31191919307544025, 0.43147756765222467, 0.6044161429674688, 0.802822908558352]`

`[0.1299952845380375, 0.2878917174206526, 0.46604190257157474, 0.5946397635273117, 0.6954389558125624, 0.8564797381595516]`

You can see that the difference between any two sequential numbers never goes lower than 0.1 and never goes higher than 0.2. Also, the first value is always between 0.1 and 0.2, and subtracting the final value from 1 also fulfills both conditions.

**TL;DR:**

You’ll probably have to make a custom node or workflow rather than being able to leverage Lunchbox to do this.

3 Likes

many thanks i will try this later