mercredi 17 mai 2023

distribute value randomly to elements of a list

I want to randomize the elements of rand_skill = [] in a way, that the sum of all elements is always equal to the variable skill_points. Further, I'd like to be able to influence the distribution, by using tag_list = [], to make specific elements of rand_list more likely to be bigger.

def roll_talents(skill_points, tag_list):
    talents = []
    # FIGHT
    talents[0] = 0 + get_attribute_mod(attributes[3]) + get_attribute_mod(attributes[4]) + rand_skill [0]
    talents[1] = 0 + get_attribute_mod(attributes[4]) + rand_skill [1]
    talents[2] = 0 + get_attribute_mod(attributes[3]) + rand_skill [2]
    talents[3] = 0 + get_attribute_mod(attributes[0]) + rand_skill [3]
    talents[4] = 0 + get_attribute_mod(attributes[5]) + rand_skill [4]
    talents[5] = 0 + rand_skill [5]
    # COMMUNIKATION
    talents[6] = 0 + get_attribute_mod(attributes[2]) + rand_skill [6]
    talents[7] = 0 + get_attribute_mod(attributes[3]) + rand_skill [7]
    talents[8] = 0 + get_attribute_mod(attributes[6]) + rand_skill [8]
    talents[9] = 0 + get_attribute_mod(attributes[1]) + rand_skill [9]
    # [...]
    return talents

I tried to use a for loop, that adds 1 to a random element of rand_skill, until the added value equaled skill_points, but that seems very inefficient and crude.




Aucun commentaire:

Enregistrer un commentaire