Can Java's random function be zero?

Posted by ThirdD3gree on Stack Overflow See other posts from Stack Overflow or by ThirdD3gree
Published on 2010-06-17T20:53:22Z Indexed on 2010/06/17 21:03 UTC
Read the original article Hit count: 297

Just out of curiosity, can Math.random() ever be zero?

For example, if I were to have:

while (true){
  if (Math.random() == 0)
    return 1;
}

Would I ever actually get a return of one? There's also rounding error to consider because Math.random() returns a double.

I ask because my CS professor stated that random() goes from 0 to 1 inclusive, and I always thought it was exclusive.

© Stack Overflow or respective owner

Related posts about java

Related posts about random