Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1.  
  2. from matplotlib import pyplot as plt
  3.  
  4.  
  5. #GCL
  6.  
  7. def GCL(multi, inc, mod, x0):
  8.     #x0 = valor anterior
  9.  
  10.     return ((multi * x0) + inc) % mod
  11.  
  12. def realizacionesGCL(cantidad=100000):
  13.     x0 = 96771 # = 0.15*74620 + 0.25*100608 + 0.6*100710
  14.  
  15.     multiplicador = 1013904223
  16.  
  17.     incremento = 1664525
  18.  
  19.     modulo = 2**32
  20.  
  21.     resultados = []
  22.  
  23.     iteracion_actual = x0
  24.  
  25.     for i in range(cantidad):
  26.  
  27.         iteracion_actual = GCL(multiplicador, incremento, modulo, iteracion_actual)
  28.         resultados.append(iteracion_actual)
  29.  
  30.     return resultados
  31.  
  32. def realizacionesEstandarGCL(cantidad=100000):
  33.     return [i/(2**32) for i in realizacionesGCL(cantidad=cantidad)]
  34.  
  35.  
  36.  
  37. if __name__ == "__main__":
  38.    
  39.     resultados_A = realizacionesGCL(cantidad=5)
  40.  
  41.     print(resultados_A)
  42.  
  43.     resultados_B = realizacionesEstandarGCL()
  44.  
  45.     plt.title('Distribucion de realizaciones con GCL')
  46.     plt.ylabel('Cantidad de ocurrencias')
  47.     plt.xlabel('Muestra generada')
  48.     plt.hist(resultados_B)
  49.     plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement