Fixing the integer arithmetic where it would hit out of bounds when RAND_MAX was reached