A homomorphism height function on the d-dimensional torus Zdn is a function on the vertices of the torus taking integer values and constrained to have adjacent vertices take adjacent integer values. A Lipschitz height function is defined similarly but may also take equal values on adjacent vertices. For each of these models, we consider the uniform distribution over all such functions with predetermined values at some fixed vertices (boundary conditions). Our main result is that in high dimensions and with zero boundary values, the random function obtained is typically very flat, having bounded variance at any fixed vertex and taking at most C(logn)1/d values with high probability. This result matches, up to constants, a lower bound of Benjamini, Yadin and Yehudayoff. Our results extend to any dimension d.2; if one replaces the torus Zdn by an enhanced version of it, the torus Zdn.Zd02 for some fixed d0. Consequently, we establish one side of a conjectured roughening transition in two dimensions. The full transition is established for a class of tori with nonequal side lengths, including, for example, the n..110logn. torus. In another case of interest, we find that when the dimension d is taken to infinity while n remains fixed, the random 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 have consequences also for the related model of uniform 3-coloring and establish that for certain boundary conditions, a uniformly sampled proper 3-coloring of Zdn will be nearly constant on either the even or odd sublattice. Our proofs are based on the construction of a combinatorial transformation suitable to the homomorphism model 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äggström and Mossel.