Kendall Ponder wrote:In the code above, doesn't x contain an integer between -1 and 1024?
So after applying the multiplication, you'll get: 0.0 * 1024 <= value < 1.0 * 1024. So it's an int value between 0 (inclusive) and 1024 (exclusive).Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0.
Roel De Nijs wrote:
Kendall Ponder wrote:In the code above, doesn't x contain an integer between -1 and 1024?
No! Your code as-is always returns 0 But even if you would use the adjusted code (notice the parantheses), it's still incorrect.Why? Just keep reading.
From the javadoc of the Math.random() methodSo after applying the multiplication, you'll get: 0.0 * 1024 <= value < 1.0 * 1024. So it's an int value between 0 (inclusive) and 1024 (exclusive).Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0.
Hope it helps!
Kind regards,
Roel
Kendall Ponder wrote:but isn't an integer between -1 and 1024 the same as and integer between 0 (inclusive) and 1024 (exclusive)? There is no integer between -1 and 0. Also, do you consider saying between 0 and 1024 the same as saying between 0 (inclusive) and 1024 (exclusive)?
Junilu Lacar wrote:The idea may be that since programmers are familiar with this idiom, it will be more consistent to use [from..to) when dealing with ranges in other contexts.