A General Model of Optimal Reproduction in a Randomly Varying Environment