Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.87 KB | None | 0 0
  1. from __future__ import print_function
  2. import numpy
  3. import matplotlib.pyplot as plot
  4.  
  5. numpy.random.seed(hash("rafa culiao") % 2**32)
  6.  
  7. def drawAges(people, maxAge):
  8.     return numpy.random.randint(0, maxAge + 1, size = people)
  9.  
  10. maxAge = 50
  11. sampleSize = 20000
  12.  
  13. people = range(201)
  14. chances = []
  15.  
  16. for n in people:
  17.     ratios = []
  18.     for i in range(40):
  19.         ages = drawAges(n, maxAge)
  20.         samples = drawAges(sampleSize, maxAge)
  21.         inclusion = [x in ages for x in samples]
  22.         trues = inclusion.count(True)
  23.         trueRatio = float(trues)/sampleSize
  24.         ratios.append(trueRatio)
  25.     percent = numpy.mean(ratios)
  26.     chances.append(percent)
  27.     print("n = {}: {}%".format(n, percent))
  28.    
  29. plot.plot(people, chances)
  30. plot.title("probabilidad de encontrar a alguien con la misma edad en una sala de x personas")
  31. plot.axis("tight")
  32. plot.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement