Fix for the error: n is not positive thrown by the function that generates random number in the specified range