jeudi 5 avril 2018

Generating random numbers to obtain a fixed sum(python)

I have the following list:

Sum=[54,1536,36,14]

I need to generate 4 other lists, where each list will consist of 6 random numbers starting from 0, and the numbers will add upto the values in sum. For eg;

l1=[a,b,c,d,e,f] where a+b+c+d+e+f=54
l2=[g,h,i,j,k,l] where g+h+i+j+k+l=1536

and so on upto l4. And I need to do this in python. Can it be done?




Aucun commentaire:

Enregistrer un commentaire