lundi 7 décembre 2020

How to calculate a probability of numbers matching up between two sets of lists? (python)

I'm trying to make a lottery program with a coupon of 6 elements of my choice from 1 to 10. (I changed the numbers to be simple for the sake of this example). The following script does the job of generating random 6 elements of numbers in the range of 1 to 10 and it finds the intersection between them and between my coupon, but I would like to calculate the chance of(ratios), for example, 4 matchup numbers between the generated random numbers and between my coupon. any ideas?

import random
from collections import Counter
mc = [9, 6, 5, 4, 8, 1]
mycoupon = set(mc)
for _ in range(100):
    r = random.sample(range(1, 10), 6)
    draws = set(r)
    
    cc = Counter(mycoupon)
    dc = Counter(r)
    common = cc.keys() & dc.keys()
    counts = 0
    for cel in common:
        counts += min(cc[cel], dc[cel])

    print("My coupon: ", mycoupon)
    print("Draw: ", draws)
    print("Matches: ", counts)



Aucun commentaire:

Enregistrer un commentaire