import random
def lst_Covering(lst,num,istrue=True):
    index = 0
    while num>0:
        if istrue:
            lst[index] +=1
        else:
            print(num,index,lst[index])
            lst[index] -=1
        index+=1
        num= num-1
        if index >= len(lst):
            index = 0
    return lst

def set_allocation_num(gdp,count):
    """分配"""
    res = []
    for i in gdp:
        res.append(round(count*i/100))
    _sum = sum(res)
    if _sum > count:
        _temp = _sum - count
        res = sorted(res,reverse = True)
        res = lst_Covering(res,_temp,False)
    elif _sum < count:
        _temp = count - _sum
        res = sorted(res)
        res = lst_Covering(res,_temp)
    return res

def get_array(name,gdp):
    lst = []
    for i,v in enumerate(gdp):
        temp = [name[i]] * int(v)
        lst.extend(temp)
    random.shuffle(lst)
    return lst

feature_name = [1,2,3,4]
feature_gdp = [70,10,17,3]
model_count = 10
feature_gdp = sorted(feature_gdp,reverse=True)
gdp_num = set_allocation_num(feature_gdp,model_count)
# print(len(test2(feature_name,res)) - model_count)
print(get_array(feature_name,gdp_num))