I have a value (a sum) (in the implementation it is n) that I want to distribute "randomly" to become a list of 12 elements summing up to that value (sum), I wrote the following method to achieve that:
def create_list_summing_up_to(n): 
    values = []
    for i in range(1,13):
        value = random.randint(0, int(n / i))
        values.append(value)
        n -= value
        if n<=0 and i<12:
            values.extend(np.zeros(12-i).tolist())
            break
    if n>0:
        for idx,el in enumerate(values):
            values[idx] = values[idx]+int (n/12)
    return values
My question is: is the method efficient even for large sums (of the order of millions)? How could it be more efficient?
 
     
     
     
    