0

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.

  • Have a look on random package in python. There are methods like choices that allow to weight random sample from a list. – jlandercy May 17 '23 at 16:58
  • [A weighted version of random.choice](https://stackoverflow.com/q/3679694/19381879) this was what I was looking for, thank you for the key words. – aGuyCalledT May 17 '23 at 17:09

0 Answers0