In [1]:
%matplotlib inline
import matplotlib.pyplot as plt
import time
import math
def random(n):
lastXn = int(time.clock())+7897857
a = lastXn*8
b = a + 98756465
m = 900217+int(time.clock())
rList = []
for i in range(n):
Xn = float((a*lastXn + b)% m)
lastXn = Xn
random = float(Xn/m)
rList.append(random)
return rList
def genExponencial(n,l):
px = random(n)
xList = []
for i in px:
r = -math.log(1-i)/l
xList.append(r)
print xList
plt.hist(xList)
def genCauchy(n, xo, v):
px = random(n)
xList = []
for i in px:
r = math.tan(math.pi*(i-0.5))
xList.append(r)
print xList
plt.hist(xList)
def main():
#Distribucion Exponencial
'''
l = float(raw_input('Please input the lambda value: ')) #l > 0
n = int(raw_input('Please input the amount of random numbers to generate: '))
genExponencial(n,l)
'''
# Distribucion de Cauchy
xo = float(raw_input('Please input the x0 value: '))
v = float(raw_input('Please input the v value: '))
n = int(raw_input('Please input the amount of random numbers to generate: '))
genCauchy(n, xo, v)
main()
In [ ]: