Let's rewrite the problem. Suppose that your f
existed. Then you can use a binary search can find the time of the next event to whatever precision that you want. So construct f
first.
So how can we create f
? Well, we only need to calculate f
from 0
to any arbitrary t
and then f(s, t) = f(0, t) - f(0, s)
.
We don't even need to be able to calculate it directly for every t
. If we can calculate it at every integer, and also if we have it at both ends of an interval if we can calculate it at the midpoint, that is enough. Since f
is non-decreasing and always an integer, a bisection algorithm will eventually wind up with t
sandwiched between two points that we know f
at which have the same value.
And now we have an approach. We will calculate it at integers. Then once we have t
sandwiched, start bisecting until we have lower and upper bounds for f(0,t)
that are the same.
We can go from integer to integer by generating a random number, then using a Poisson distribution to find how many events happened. If we know f
at two ends of an interval, we can find it at the midpoint with the same trick, but this time knowing that the number of events that happened in the first half of the interval is described by a binomial distribution.
The trick to worry about that we need a pseudorandom generator with 2 unrelated "move next" options. One of them for when we move next interval/land in top half of an interval. The other for when we stop moving intervals/land in bottom half of an interval. And we need paths we walk between the two to not give the same answer. Else your random events will be distributed in an oddly periodic manner. I would suggest doing this by having two different generators that use seeds in the same range. (If they are close, but not the same, you can just repeat the one you're doing until the seed winds up in the common range...) Which generator you use depends on which direction the last flip took you.
Figuring out the right ones to use may require some thought. But hopefully that is easier to figure out than the problem you started with!