Created
March 17, 2015 16:55
-
-
Save ryanseys/c5ae910766fbc4cf3d12 to your computer and use it in GitHub Desktop.
First N Packet Poisson Arrival Times
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function firstNPacketPoissonArrivals(n, rate, t) { | |
n--; | |
t = t || 0; | |
var u, x; | |
var lambda = rate; | |
u = Math.random(); // random value between [0, 1] | |
x = (-1/lambda)*Math.log(1-u); | |
t = t + x; | |
console.log('Arrival of packet at time: ' + t); | |
if (n > 0) { | |
firstNPacketPoissonArrivals(n, rate, t); | |
} | |
} | |
firstNPacketPoissonArrivals(10, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment