Incidentally, the above assumes that the RNG returns integral-type values.  In principle, there's no reason why RNGs shouldn't return floating-point values.