This paper addresses the financing of public pensions in a stochastic environment. Traditionally, funded and unfunded pension schemes have been viewed as opposite solutions for the first pillar of public pensions. However, more recently countries as Sweden and Poland have explored mixed solutions that combine pay-as-you-go (PAYG) with funding mechanisms. The aims of this paper are to examine the rationality of such a combination using portfolio theory arguments and to find the optimal split of the contributions between the two systems. We first introduce the classical deterministic model leading to the well-known Samuelson–Aaron rule according to which diversification is never optimal. We then introduce different stochastic models in which the main processes (wage growth, population growth, financial rate of return) are random. In particular, we obtain conditions on parameters to justify diversification and explicit optimal sharing between PAYG and funding. We also introduce the possibility of investing in several financial assets and explore the impact of introducing systematic longevity risk.