In [3]:
%matplotlib inline
import matplotlib.pyplot as plt
import time
import math
import numpy as np
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 genLaplace(n, u, b):
px = random(n)
xList = []
for i in px:
r = u - b*np.sign(i-0.5)*math.log(1-2*abs(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)
'''
#Distribucion de Laplace
u = float(raw_input('Please input the u value: '))
b = float(raw_input('Please input the b value: '))
n = int(raw_input('Please input the amount of random numbers to generate: '))
genLaplace(n,u,b)
main()
Please input the u value: 0
Please input the b value: 10
Please input the amount of random numbers to generate: 500
[60.354092375360565, 30.057645798054793, -10.718116978298637, 45.136413134587073, 7.4904322762820819, -7.9940198859218228, 2.8061360676791276, -0.77416500626250251, 0.34640384875125502, -11.066697029695991, -1.8816036138599455, 0.52954516619229952, 9.929490332352394, 12.567149775476237, -21.556370482557661, -27.389191924171108, 0.11145882112162198, -11.882072311564622, -14.584895178338169, -1.12296104342355, -1.0666252400070597, 4.0653642763385065, -21.834260667284436, 7.4878015503274824, -12.525552831368278, 10.461901280871675, 2.560508409692706, -6.0124132659344545, -26.093003514039211, 0.060975900583223691, 0.73554724251200676, -37.312469303170147, 16.12772329917696, -7.84142601774019, 15.01442881120688, 9.5428750099800936, -4.6762482879305827, -2.714122238614602, -13.578449759803508, -4.9295572940990589, -1.7363944124220809, 2.5371474290867453, 0.97035523772460364, -1.6633267192269041, -8.8289080159039486, -17.278495423724749, -0.77421301186955838, -11.586467304958351, -12.958688743113811, -16.278411081984519, 17.144483618910435, -30.178191739593746, 0.074977119589641289, -7.4725944920741938, 19.983541808199391, 10.69983709662997, 32.136766974385303, -6.7720377026839884, 2.2446842138288505, -4.7063628025781785, 5.5233209439270317, -24.088300190662942, -5.3068934320079739, -4.695343439377571, 0.46634004414764818, -0.78326618728260256, -5.6534131115820525, 7.5390371052795349, -32.171079919667925, -4.2186779460145756, 1.097864435667935, -5.7942172521911983, 25.939619841304516, -20.631920923615535, -8.9283388130563814, -0.70551331839333042, -8.4389260617979307, -20.93385811372498, 27.080912990391546, -7.8790636685753901, 16.320586580711243, 9.5076899644531192, -4.7038023837934766, 4.2972324111425388, -19.529111078008995, 4.2287093968069955, -0.36322927913926673, 29.471985098289718, -8.9011428009314653, 11.588732118262485, -3.0568936971933462, -2.3876182002815378, 0.77901473674135802, 2.0805426660479491, 6.8946522555398184, 15.96270615355251, -1.3403753856264298, 2.5868585074805917, -3.1368287217830138, -15.734791806544253, 18.148779698639867, -2.512898337983041, 13.224636268335882, 4.9842230636369447, -9.4198378142300001, 8.3967074368396979, -7.5737985281846063, -2.2586242904611673, -7.5657003839218495, -9.9559082061889939, 4.1950962611259985, 5.3874344448216789, 10.436700179908209, 8.1791831188406512, 1.9475408453996335, -0.36781456965397341, -12.24433423676841, -3.0208599002621406, 15.575239114093222, 2.088067419420089, -6.598385654020622, 10.068178929094568, -2.3285335426425271, 8.6373893706706664, 0.66768171175639157, -5.9878429803659063, -4.5407246246359882, -11.87201847168118, 25.511880949226182, -1.9035612910891577, -6.6219630616195282, -11.482276229492916, 1.9203977155249452, -9.805068224078628, 9.0451658227190777, 6.2066743861584603, -4.1753804459693402, -10.456843335680489, 0.70053230690670931, 16.285427990758365, 48.779033928178485, 15.607560240725075, 4.6099475156466161, 2.7138891091723827, -10.488814595135555, 2.6549074868332188, 5.3052695741335096, 4.7781070593721502, 16.142221550774181, 3.0841330304558889, 6.5794092571891563, -3.5199055038249201, -3.8114281718474348, 6.9702336361053598, -12.964291461796844, 4.3331097417629731, 19.206917565469848, 2.7504694068421962, 7.2545143511139312, -0.59084251305530311, -8.2004968697385401, -61.006288943388199, 0.54400743380378025, 15.685410573637984, 3.558167163091932, -20.590914732684837, 0.25873128898219455, 9.9205001669871287, 12.213545245159382, 18.385633965843382, -4.2315240772491354, -4.4927053246819151, 14.231149986581823, 1.4718478991673691, 13.141287232790855, 21.537401507421325, 14.991921307506352, -14.292831483090961, -16.837484855802177, 4.0308652927414332, 0.85458467040379749, -62.557711458884086, -1.7073403887462371, 10.76670133373595, -7.5489566163525161, 17.938353594677142, 5.6446588022616151, 3.6142889401161957, 10.444020270095489, 3.953740980676792, -7.2801526811156094, 9.8713770515026535, 13.057725300084076, -8.8034807274285125, -1.6247835592597619, -8.3446825076647428, -20.522884898275894, -17.584594488643049, -2.220717139709969, 9.2235367923557394, 2.7755954160957996, -7.8859043493921384, 5.0238314291343809, 9.7729633798933442, -9.7883821258774066, 1.4447063068033534, 6.9150797329380262, 15.550908842515636, -43.682456523962671, 27.124662120901839, 9.7747934815281283, 7.7189672168824996, -40.177245740319165, -12.134293515129402, 21.140152355882282, 7.1769440887047731, 23.72395321317822, -25.597701197324252, -4.4482076211661168, 0.065357561168530517, 10.336651015859356, 9.4109525699847225, 13.834582443966868, 1.7104765853561241, -3.9016577866501305, -0.066989997001214496, 8.1827070818251642, -9.630073664416404, -0.42043064196990731, -8.7123891933184598, 18.751633413521951, 1.173019266700903, 33.947614503290716, 49.284751255304414, -4.4384730350786006, -16.836049260206988, 10.571782014814312, 5.5147182950924307, 15.83245230268188, -14.572104889576661, 1.5423583959072842, -3.3167937955347271, 11.605238272853658, -4.5803322460174885, 5.584563005886034, 12.65677177784953, 11.204970837714024, -4.4755566891523832, 3.1842124272861891, 2.0696896360444295, -5.9593813994003888, -7.2736679694005391, -9.2385223408185002, 13.760252349538177, 38.981324761273683, -3.8471351651487984, -1.4261147225359734, 0.39176595842367795, -0.56518771354306119, -0.89002275030307731, 0.68636548608331693, 8.2817330723762801, 0.36023499819345761, -3.1238564432685481, 31.345694037538578, -50.693119240551539, -3.047609429139543, 11.667897392176414, 19.152026793079816, -6.2422754603298767, 1.8716874714448988, 2.3730184643165662, 22.805560114129683, -21.072131742516117, 8.2394119476307086, -3.0322851398564978, -0.37293230062835703, -10.250896850172317, -8.8561773129092849, 9.7562717899339333, -7.4145140639356155, 0.71770223133244104, 0.54405434714077139, -6.6984549433302085, 4.406736963831829, -2.7483345574652573, -13.579745337136169, 2.3546159852004229, -8.8403552911711003, 6.5994600563853396, -1.5644660525488279, 48.525491104476913, -22.63235457772182, -1.4917625535779551, 5.5166850644102281, -18.440536833485645, 11.594538044718632, -13.385905010720601, 1.3299917618753889, -0.078043900445177811, 11.554108246927841, -11.935131363610122, -1.9478647434041807, -15.926596735726548, 5.7282145859071596, -13.912147722283649, -10.460446859586503, -6.0924104373448014, -17.185155439005939, -0.23559641332856557, 11.656702336796748, 3.885590839782203, -27.918815645471774, -6.004148970056038, 7.4975292918385472, -1.9856166589327637, 7.9419293762752039, 10.533428303620001, 0.23123047485532941, -4.0542623323582188, 3.2597270604161261, -33.481872591111028, -2.9504923226075732, 29.921255735851698, -18.233022733172625, 3.1237957227589819, -2.0890528973092266, -47.447733062675368, 5.2999466800900876, -4.9391632330540594, 15.258872643378707, 12.049955710674162, 10.540373389932212, -13.082186428955538, 14.832540050223875, -3.1581312252740275, -18.355788193221425, 21.868037476381311, 7.6080631775605969, -4.1617304532026971, -17.197674575705143, -4.9459365986923824, -2.1088103069393411, -9.1763784628581675, -1.4677050719244806, 13.011919322483656, -2.5309079651347473, -1.1597140728425086, 5.7631773108870412, 3.1371935255186436, 9.2026615894189092, -5.5020785042782858, 15.886373656266674, 2.0680777220843591, 3.6674892280058087, -2.2098495321475302, -2.8876710578621645, -8.8178493933468527, -10.448819098263254, -2.2774366118053608, 5.5022325518789987, 1.4221700604578302, -0.0084562466528991208, -3.0372802651995845, 2.1326478277015299, 9.8859931431375472, 29.144728584064453, 5.0572963240972477, 3.3661286520901479, -11.712158382186271, -2.8351478473629932, 22.568698741813023, -0.34327665710480376, -20.657832663169124, 1.2713708389176288, -3.3686795772809912, 10.569927954897294, -0.18247079926082482, -0.32299665764149327, -27.028068757542524, -12.582461082271891, -2.2454905948053692, -8.6392338106117084, 17.209961037943387, -6.4429603376147302, -24.825579899234388, -3.9789090285762665, -4.5698718104290954, -3.1709955511071639, -15.57302482347435, 19.738302541308251, -18.738602586537255, -2.4391692977464734, -3.9979758210693954, 2.6638340663146129, -11.623902475303227, -18.476696114243371, 1.6109944160234457, -0.64081078151445858, -1.0983602964699912, 12.964616353364312, 8.5972648943167513, -11.01162446557244, -2.1739209026099529, -7.3836938117860464, 5.6997743531407208, 25.182668851911764, 13.721015442887968, 0.29630269306804113, 28.390315917070925, -5.339236638345497, -2.6538936068149122, -3.8746538605724985, 11.698694899842891, 0.43032850013523605, -1.9989558143082131, -9.3024626492093212, 9.9327887524390892, 7.322383018742479, 11.497485144706999, -8.0255437194304218, 21.301500019895656, -2.593737621008267, -3.5522078384747298, 0.54834784912061962, -9.0563689519799304, -5.590622411550533, 9.1500533043663363, 30.413496713695707, -1.7962456261534054, -16.612945066848326, -2.9927433165213864, 1.9034806735588738, 22.27179834058343, 11.065017593713824, 10.726555140059077, -11.778955439546724, -13.875246982507175, 5.4403045288668999, -10.717208677728383, 0.30456676850566278, 26.059850982167639, -1.3410358339186494, 20.111026609876582, 45.826631448506774, 45.705731875727551, 17.476881806700192, -14.702392699221235, -6.3438110236552392, -31.157080755197924, 15.477540172887176, 33.487562491691286, 41.483677254178986, -9.7112903681193679, -7.6806811186162349, -2.1742246068351925, -6.5943898903362106, 1.2893734166579427, 5.8463781465057938, 35.902000471482495, 4.0923536740034736, 0.49013224076827211, -5.8989728260466032, 10.960641859133586, 2.6297068595388406, 15.713063952638491, -5.8503650058703123, 7.1101425423849509, 21.735171275250234, -20.671340370754969, 5.0108800792648003, -6.5475909414666216, -11.534658471938585, -5.7308542258283257, 1.2187611867205554, 16.671373992226595, -28.011280811000191, 0.95673010765184752, -12.42269593068708, -6.1702114150304315, 1.3902091431531163, -0.90149064146814406, 1.2115367316269088, -21.933146783946242, 19.17195223025773, -27.381634123818227, -0.69793553855839729, -0.70691989042465386, 2.0580023195470667, -8.1685683945688261, -12.533873949211165, 1.2944796233376969, -17.345110901246336, 13.065188629649443, 1.9949142320687101, 5.8601395342296625, -16.298116191302789, 1.839888221042115, 0.94368500247929876, -44.012107754213034]
In [ ]:
Content source: DavidVargasMora/SimulationLabs
Similar notebooks: