The long-range electronic correlations in a uniform electron gas may be deduced from the random-phase approximation (RPA) of Bohm and Pines [Phys. Rev. 92, 609 (1953)]. Here we generalize the RPA to nonuniform systems and use it to derive many-electron Slater-Jastrow trial wave functions for quantum Monte Carlo simulations. The RPA theory fixes the long-range behavior of the inhomogeneous two-body terms in the Jastrow factor and provides an accurate analytic expression for the one-body terms. It also explains the success of Slater-Jastrow trial functions containing determinants of Hartree-Fock or density-functional orbitals, even though these theories do not include Jastrow factors. After adjusting the RPA Jastrow factor to incorporate the known short-range behavior, we test it using variational Monte Carlo simulations. In the small inhomogeneous electron gas system we consider, the analytic RPA-based Jastrow factor slightly outperforms the standard numerically optimized form. The inhomogeneous RPA theory therefore enables us to reduce or even avoid the costly numerical optimization process.