Random number random reports an error. Illegalargumentexception: bound must be positive

error code

    private static Random RANDOM = new Random();
    private static Integer randomOnce(Integer max, Integer min) {
        return RANDOM.nextInt(max) % (max - min + 1) + min;
    }

Error message

java.lang.IllegalArgumentException: bound must be positive
	at java.util.Random.nextInt(Random.java:388)

Solution

private static Random RANDOM = new Random();
    private static Integer randomOnce(Integer max, Integer min) {
        if (max<=0)
            throw new IllegalArgumentException("Random positive must be greater than 0");
        return RANDOM.nextInt(max) % (max - min + 1) + min;
    }

Read More: