Java: Math.random() Max Value (double just less than 1)
double, java, math, precision, random
Solution
Java uses 64-bit IEEE-754 representation, so the closest number smaller than one is theoretically `3FEFFFFFFFFFFFFF` in hexadecimal representation, which is 0 for sign, -1 for the exponent, and 1.9999999999999997 for the 52-bit significand. This equals to roughly `0.9999999999999998`.
References: IEEE-754 Calculator.
Problem
I've been a little curious about this. Math.random() gives a value in the range [0.0,1.0). So what might the largest value it can give be? In other words, what is the closest double value to 1.0 that is less than 1.0?