  We discuss models in which the smallness of the effective vacuum energy
density $\rho_\L$ and the coincidence of the time of its dominance $t_\L$ with
the epoch of galaxy formation $t_G$ are due to anthropic selection effects. In
such models, the probability distribution for $\rho_\L$ is a product of an {\it
a priori} distribution ${\cal P}_*(\rho_\L)$ and of the number density of
galaxies at a given $\rho_\L$ (which is proportional to the number of observers
who will detect that value of $\rho_\L$). To determine ${\cal P}_*$, we
consider inflationary models in which the role of the vacuum energy is played
by a slowly-varying potential of some scalar field. We show that the resulting
distribution depends on the shape of the potential and generally has a
non-trivial dependence on $\rho_\L$, even in the narrow anthropically allowed
range. This is contrary to Weinberg's earlier conjecture that the {\it a
priori} distribution should be nearly flat in the range of interest. We
calculate the (final) probability distributions for $\rho_\L$ and for
$t_G/t_\L$ in simple models with power-law potentials. For some of these
models, the agreement with the observationally suggested values of $\rho_\L$ is
better than with a flat {\it a priori} distribution. We also discuss
quantum-cosmological approach in which $\rho_\L$ takes different values in
different disconnected universes and argue that Weinberg's conjecture is not
valid in this case as well. Finally, we extend our analysis to models of
quintessence, with similar conclusions.
