0

This code

java.util.Random r = new java.util.Random();
double a = r.nextDouble();
...
double b = r.nextDouble();

produces two random values between 0.0 and 1.0. What is the probability of a == b?

(how many distinct double values are there between 0.0 and 1.0?)

activity
  • 2,653
  • 3
  • 20
  • 44
  • 1
    This has already been answered here : https://stackoverflow.com/questions/2978930/how-many-double-numbers-are-there-between-0-0-and-1-0#2978945 – Claudio Brasser Aug 11 '17 at 08:31
  • The probability of a==b don't have to depend on number of values between 0 and 1 :) If I were to choose, I could have thrown a dice, and decide which value I'll return each time. It will be random, but always the same :) – xenteros Aug 11 '17 at 08:33

0 Answers0