Here is the format I adhere to:
int randomNum = rand.nextInt((max - min) + 1) + min;
So here is my code. I am trying to get a random even number from 1 to 100:
Random rand = new Random(); int randomNum = rand.nextInt((100 - 2) + 1) + 2;
I saw one solution - multiply the number by 2, but this violates the intended range.
I was thinking of making a bunch of if statements to solve this, but it seems too complicated. Is there a relatively simple solution?
source share