Not sure it’s really possible, although maybe you could just create a few combinations that add up to 100% (e.g. [10,20,30,40], [20,20,30,30], [10,10,40,40]) and generate permutations of them to make a pseudorandom pool of 4 values each adding up to 100%. You then just take a random ‘seed’ from that pool of permutations as your input.
Alternatively, you could set a watchable outcome for the total percentages and filter the studies where the combined percentage exceeded 100%, but it would be most of them so you’d have lots of redundant studies.
Is it viable for you to just ignore the precise input values and just use them to define the ratio? e.g. if you have 20, 30, 40, 50 you could put in a couple code blocks to math them back to 100 total (14, 22, 28, 36).
Thank you @GavinCrump for sharing this sample. It really works perfect and I started using it to explore GD more.
One thing I wish to ask: is there any reason why my “Watch” nodes “Result 1” and “Result 2” not showing any results in the Refinery study…!!? Please see attached my Dynamo example code.
from random import randint
from math import floor,ceil
precision = float(IN[1]) if IN[1]>0 else float(1)
def genRan(rndp):
#Generate 1st random number and assign it to sum
sum = ceil(float(randint(1,50))/rndp)*rndp
#Add the 1st number to output list
out = [sum]
#Generate all other numbers except 1st & last
for i in range(IN[0]-2):
num = floor(float(randint(0,100-sum))/rndp)*rndp
out.append(num)
sum += num
#Add last number to list
out.append(100-sum)
if 0 in out:
return genRan(rndp)
else:
return out
OUT = genRan(precision)
Try making them watch nodes at the end of the code instead of partyway through, and set them to ‘Is output’. Make sure output 2 is a watch node instead of a round node.
Thanks @GavinCrump … after several attempts and search in Dynamo forum, I realized that I should add the “Data.Rememebr” node for it to work with Refinery.
Thanks @GavinCrump and @AmolShah and @Hamish for all your feedback.