I am trying to improve an algorithm that looks like the following (and am getting stumped): I am provided with a starting time, rate, and a target time. I then use an exponential distribution to generate times with the given rate, summing them, until I get a time greater then the target time, which I return. In code, it looks like this:
def generateTime(start, rate, target):
current = start
while(current < target):
current += (-1.0/rate)*log(random()) # where random returns [0, 1)
return current
My intuition tells me there is some way to do this without having to to do the loop though, and to just use a closed form solution that does not have a loop, which might be run once, or many thousands of times, depending on the parameters of the simulation. Does such a better solution exist?