Skip to content

Instantly share code, notes, and snippets.

@sachinsdate
Last active September 19, 2019 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sachinsdate/d48abefe2f75541c7d98f51599c927b0 to your computer and use it in GitHub Desktop.
Save sachinsdate/d48abefe2f75541c7d98f51599c927b0 to your computer and use it in GitHub Desktop.
Simulate a Poisson process
import random
import math
_lambda = 5
_num_arrivals = 100
_arrival_time = 0
print('RAND,INTER_ARRV_T,ARRV_T')
for i in range(_num_arrivals):
#Get the next probability value from Uniform(0,1)
p = random.random()
#Plug it into the inverse of the CDF of Exponential(_lamnbda)
_inter_arrival_time = -math.log(1.0 - p)/_lambda
#Add the inter-arrival time to the running sum
_arrival_time = _arrival_time + _inter_arrival_time
#print it all out
print(str(p)+','+str(_inter_arrival_time)+','+str(_arrival_time))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment