vendredi 23 avril 2021

Give lower values a higher weight in a `randint()` function

Using randint() how do I give lower values a higher weight (higher chance to be picked)?

I have the following code:

def grab_int():
    current = randint(0,10) 
    # I want the weight of the numbers to go down the higher they get (so I will get more 0s than 1s, more 1s than 2, etc)

Is it possible to do with only 1-2 lines of code, or do I need an entire function for giving them weight?




Aucun commentaire:

Enregistrer un commentaire