It is perfectly possible that it will never return exactly zero. Java's included PRNG is a 48-bit LCG from which only 32 bits are ever used. For all 53 bits of a double
mantissa to be zero you'll essentially need at least one call to next()
where the upper 32 bits are zero and another where most of them are. (If I'm not mistaken I'd say this won't ever happen with how the generator works but it's late, I'm tired and I won't bet much on it.)
Since the method documentation explicitly states how random numbers are obtained there is also little leeway for other implementations of the Java runtime to yield different results. The contract might say that the number you get is from [0, 1). But in practice there are quite a number of values you'll never hit (because you need two successive values from a generator that foribly yields a linear dependency between successive values – there are only 48 bits of state. You can't generate all different 53-bit combinations from that – at least not how it's done.).
Of course, since Math.random()
automatically seeds a static Random
instance we might also have to consider the seed here which may need to be very specific for s test case to work out. And that might mean that that exact point in time could be a few decades or millenia away.