jeudi 5 septembre 2019

Is there a reverse way to find number of people with given 0.5 probability that two people will have same birthday but no using mathematical formula?

I'm doing birthday paradox, and want to know how many people can meet 0.5 probability that two people have same birthday by using python.

I have tried no using mathematical formula to find probability with given the number of people by using random and randint in python

import random
def random_birthdays():
    bdays = []
    bdays = [random.randint(1, 365) for i in range(23)]
    bdays.sort()
    for x in range(len(bdays)):
        while x < len(bdays)-1:
            print x
            if bdays[x] == bdays[x+1]:
                #print(bdays[x])
                return True
            x+=1
        return False
count  = sum(random_birthdays() for _ in range(1000))
print('In a sample of 1000 classes each with 23 pupils, there were', count, 'classes with individuals with the same birthday')

I expect some hints or codes that can help me through this.




Aucun commentaire:

Enregistrer un commentaire