Corrected a problem of converting the output of rand to integer. We needed to floor first and then round or we will produce integers that reach n-1 (that we don't want).