Random Distribution Totaling Sum Number of Items


I would like to ask if the following can be achieved (red group)?

  1. Analyze a list for its total number of items (x)
  2. Define a specific number sub-groups (y)
  3. Arbitrary random distribution of (x) by (y)
  4. the sum of the sub-groups (y) should total the number of items if (x)

I have attached a solution for a discrete value in each of the sub-group (green group) but want to know if GH could randomize these values based on the criteria above.

Thanks in advance for the help.

random distribution.gh (25.5 KB)

Note: Added the scripting tag to see if the scripting channel can shed any light on this.

This kind of works…? by thinking about it as a math problem.

I also have noticed if I change the slider in (Y) to “6” I get a total sum of 101 and not 100? not sure why that is happening.

I would like to ask the experienced GH users and/or the more proficient at mathematics if a “better” and more efficient solution exists. A component, expression or some other coded script perhaps?

Any help would be greatly appreciated.

random distribution1.gh (22.2 KB)

Thank you.

Not a tremendous difference, but another approach.

random distribution1-b.gh (21.3 KB)

There is the possibility that there could be duplicates in the random numbers,depending on the seed, so I included the Delete Consecutive component to alert you.

Thank you for Ethan.

Thank you for your time - it is much appreciated!

There seems to be 6 lists coming out of the partition, this should match the slider connected to “N” of Random Integers.

Also when the seed increases, the number of resulting lists out of the partition increases.

I was playing around with it and realized that it was not working under all circumstances, I was just “lucky”. Here’s a revised version, which of course, is that much more complicated.

random distribution1-c.gh (22.8 KB)

Also, the more random numbers you generate, the more likely you’re going to have duplicates.I’m thinking this is something probably better done programmatically, where you can loop to your heart’s content until you find a suitable list without duplicates.

1 Like

Hmmm. I see what you mean. It appears to work up until about 12 and then starts to output mismatched lists. Same applies to the seed - but its not as bad. It does work as long as I know where the errors are hiding and avoid them.

I do like your approach - its getting me to think some more, so thank you for that. I appreciate your time in helping.