mercredi 31 octobre 2018

Generate Random numbers from tuple list in Python

I have a tuple list containing numbers with a certain probability assigned:

    import random
    my_randoms = [random.randrange(1, 51, 1) for _ in range(10)]

    weights = [0.1, 0.2, 0.05, 0.03, 0.15, 0.05, 0.2, 0.02, 0.09, 0.11]

    aa = list(zip(my_randoms, weights))    

    aa
        Out[40]: 
    [(7, 0.1),
 (5, 0.2),
 (47, 0.05),
 (21, 0.03),
 (13, 0.15),
 (32, 0.05),
 (41, 0.2),
 (1, 0.02),
 (47, 0.09),
 (19, 0.11)]

I would like to randomly generate 100 numbers from the list given the probability distribution that I assigned. How could I do this? Thanks!




Aucun commentaire:

Enregistrer un commentaire