rand/rand.c: Rearrange some comparisons to avoid arithmetic overflow.