Skip to content

Instantly share code, notes, and snippets.

@ryanseys
Created March 17, 2015 16:55
Show Gist options
  • Save ryanseys/c5ae910766fbc4cf3d12 to your computer and use it in GitHub Desktop.
Save ryanseys/c5ae910766fbc4cf3d12 to your computer and use it in GitHub Desktop.
First N Packet Poisson Arrival Times
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