Hi! I know this isn’t tagged Java but my question is kinda related. The Java article Static Methods of the Math Class says the two lines of code below differ. Anyone knows why?
(int)(Math.random() * 10) + 1; // returns integer between 1 and 10 (int)(Math.random() * 10 + 1); // returns integer between 0 and 10
From what I read the
(int) typecasts the element on its right to an integer and works similar to
Based on this information I would assume that both lines of code return the same range, which I used a while loop to check for. But I just want to be 100% sure.