The Poisson distribution function is given by:
f(x) = P(X=x) = (e^(-λ) * λx )/x!
I am writing some code and need to determine the number of events that will happen in a time step. Of course this is variable/random.
In other words:
Given our input is the standard math.random() value of [0,1), I need to find out how many events are going to happen in time interval t, given that the number of events in t is distributed according to Poisson.
One potential solution:
With the Exponential distribution, we can find the CDF, then solve for x (invert it), and then input y, where y is [0,1), and that would tell us if the next event happened in our time interval. If it did, then we would do it again for (t-x), and then, if it again happened within our time interval, we would do (t-x2), etc.
So we can invert the exponential, but I am wondering there is a way to invert the Poisson and do something similar?
There is no explicit way to invert the CDF of the Poisson, but you can use the inverse CDF method anyway, you just need to loop to find the first $k$ for which your math.random() exceeds your CDF.
https://math.stackexchange.com/a/3693297/71809
The last algorithm in this wikipedia section does the exact same thing but is a bit smarter with the way computations are performed
https://en.wikipedia.org/wiki/Poisson_distribution#Evaluating_the_Poisson_distribution
Anyway these won't give you an algorithm that's much efficient than your exponential method. In particular both methods are linear in $t$ so if your $t$ is large there are other, better ways.
https://www.johndcook.com/blog/2010/06/14/generating-poisson-random-values/