I'm trying to make a random number generator starting with the number 0 and going to 3. Right now I have this:
Random dealerNum = new Random();
int dealer = dealerNum.nextInt(3);
I'm trying to make a random number generator starting with the number 0 and going to 3. Right now I have this:
Random dealerNum = new Random();
int dealer = dealerNum.nextInt(3);
you can use Min + (int)(Math.random() * ((Max - Min) + 1))
for generate random number.
A random integer value in the range [Min, Max] Min = 0 and Max = 3
0 + (int)(Math.random() * ((3 - 0) + 1))
=> (int)(Math.random() * 4)
int dealer = (int) (Math.random() * 4);
This will generate random int between 0 and 3 in java.
int dealer = (int) (Math.random() * 4);
This will give you a random int between 0 and 3. But your code also should work too.