dimanche 15 mai 2022

How to tune random.choice probability - python -

I made a function that randomly selects one from a list of texts.

def ttc(*arg):
    a = random.choice([*arg])
    return ''.join(a)

print(ttc("Price", "Condition", "Loan"))
print(ttc("entertainment", "geese", "Uruguay", "comedy", "butterfly"))

But I found it necessary to make certain words have a higher probability of being selected.

For example, can we change the probability of being selected sequentially from the front of the list by 50% 30% 20% like this?




Aucun commentaire:

Enregistrer un commentaire