issues with rand function.

it generates the same number multiple times when the ranges are close to
the max ranges.