Fix off-by-one error; simplify sampling code.

I was initially reluctant to use 0 as a magic value for simple random
sampling because I reasoned that it is would be easy to write code that
is broken somehow and unintentionally returns 0. But it would be just as
easy to get things wrong and have the random function be unintentionally
idempotent. This way of doing it seems cleaner and saner to me.

Change-Id: I69725abb7643f30173fa658fe85219fa96e86705
Merge "Fix off-by-one error; simplify sampling code."