  A homomorphism height function on the $d$-dimensional torus $\mathbb{Z}_n^d$
is a function taking integer values on the vertices of the torus with
consecutive integers assigned to adjacent vertices. A Lipschitz height function
is defined similarly but may also take equal values on adjacent vertices. In
each model, we consider the uniform distribution over such functions, subject
to boundary conditions. We prove that in high dimensions, with zero boundary
values, a typical function is very flat, having bounded variance at any fixed
vertex and taking at most $C(\log n)^{1/d}$ values with high probability. Our
results extend to any dimension $d\ge 2$, if $\mathbb{Z}_n^d$ is replaced by an
enhanced version of it, the torus $\mathbb{Z}_n^d\times\mathbb{Z}_2^{d_0}$ for
some fixed $d_0$. This establishes one side of a conjectured roughening
transition in $2$ dimensions. The full transition is established for a class of
tori with non-equal side lengths. We also find that when $d$ is taken to
infinity while $n$ remains fixed, a typical function takes at most $r$ values
with high probability, where $r=5$ for the homomorphism model and $r=4$ for the
Lipschitz model. Suitable generalizations are obtained when $n$ grows with $d$.
Our results apply also to the related model of uniform 3-coloring and
establish, for certain boundary conditions, that a uniformly sampled proper
3-coloring of $\mathbb{Z}_n^d$ will be nearly constant on either the even or
odd sub-lattice.
  Our proofs are based on a combinatorial transformation and on a careful
analysis of the properties of a class of cutsets which we term odd cutsets. For
the Lipschitz model, our results rely also on a bijection of Yadin. This work
generalizes results of Galvin and Kahn, refutes a conjecture of Benjamini,
Yadin and Yehudayoff and answers a question of Benjamini, H\"aggstr\"om and
Mossel.
