Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from __future__ import print_function
- import numpy
- import matplotlib.pyplot as plot
- numpy.random.seed(hash("rafa culiao") % 2**32)
- def drawAges(people, maxAge):
- return numpy.random.randint(0, maxAge + 1, size = people)
- maxAge = 50
- sampleSize = 20000
- people = range(201)
- chances = []
- for n in people:
- ratios = []
- for i in range(40):
- ages = drawAges(n, maxAge)
- samples = drawAges(sampleSize, maxAge)
- inclusion = [x in ages for x in samples]
- trues = inclusion.count(True)
- trueRatio = float(trues)/sampleSize
- ratios.append(trueRatio)
- percent = numpy.mean(ratios)
- chances.append(percent)
- print("n = {}: {}%".format(n, percent))
- plot.plot(people, chances)
- plot.title("probabilidad de encontrar a alguien con la misma edad en una sala de x personas")
- plot.axis("tight")
- plot.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement