mercredi 15 novembre 2017

How to randomly select values for a list?

I'm using Python 2.7

To be clear, I don't want to randomize the items in the list. I want to make it so it's possible for certain strings not to show up at all. For example:

    r = "red"
    b = "blue"
    y = "yellow"
    rc = random colour
    myColours = [rc,rc,rc]
    print myColours

Obviously the code above wouldn't work, but I'm not sure how to proceed. It would also help if I could change how likely a certain string would be selected, like 50% odds of red, 30% odds of blue, and 20% odds of yellow.




Aucun commentaire:

Enregistrer un commentaire