I've got a question regarding the usage of Math.ceil() together with Math.random() in Java in order to get the numbers from 1 to x.
int number;
number = (int) (Math.ceil(0) * 1);
System.out.println("number generated was: " + number);
This code will return 0, as expected - 0 * 1 is 0.
int randomNumber;
do {
randomNumber = (int) Math.ceil(Math.random() * 1);
System.out.println("Random number generated was: " + randomNumber);
}while (randomNumber != 0);
Then how come this will always return 1? I don't get it - when accessing the Math.random() it reads: "return a pseudorandom {@code double} greater than or equal to {@code 0.0} and less than {@code 1.0}"
That should still allow for the case 0 * 1. Can someone please explain this to me?