Skip to content

Instantly share code, notes, and snippets.

Last active September 19, 2019 10:47
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment