In response to environmental changes, cells often adapt by up-regulating genes to synthesize proteins that generate a benefit in the new environment. Several such cases of gene induction have been reported where the timing was heterogeneous, with some cells responding early and others responding late, although the microbial population was genetically homogeneous and the environment was well mixed. Here, we explore under which conditions heterogeneous timing of gene induction could be advantageous for the population as a whole. We base our study on a mathematical model that accounts for the cost of protein synthesis in terms of resources, which cells must provide immediately, whereas the associated benefit accumulates only slowly over the protein lifetime. Due to this delayed benefit, gene induction can be a risky investment, if resources are scarce and the environment fluctuates rapidly and unpredictably. Unprofitable gene induction then depletes the remaining limiting resource needed for maintenance of cell viability. We show that whenever gene induction is associated with a transient risk but beneficial in the long run, the stochastic timing of gene induction maximizes the reproductive success of a population. In particular, in an environment of stochastic periods of famine and feast, an optimum emerges from a trade-off between short-term growth, favoring rapid and homogeneous responses, and long-term survival, favoring a broadly heterogeneous response. Our analysis suggests that the optimal variability of induction times is just as large as the time required for the amortization of the initial investment into protein synthesis.