The optimal life of a patent when the timing of innovation is stochastic