public double nextDouble(){
  return ((((long)next(26) << 27) + next(27)) / (double)(1L << 53));
}

public double nextDouble ( ) { return ( ( ( ( long ) next ( 26 ) << 27 ) + next ( 27 ) ) / ( double ) ( 1L << 53 ) ) ; }
returns the next pseudorandom , uniformly distributed double value between 0 . 0 and 1 . 0 from this random number generator ' s sequence . the general contract of nextdouble is that one double value , chosen ( approximately ) uniformly from the range 0 . 0d ( inclusive ) to 1 . 0d ( exclusive ) , is pseudorandomly generated and returned . all 253 possible float values of the form mx2 - 53 , where m is a positive integer less than 253 , are produced with ( approximately ) equal probability . the method nextdouble is implemented by class random as follows : public double nextdouble ( ) { return ( ( ( long ) next ( 26 ) < < 27 ) + next ( 27 ) ) / ( double ) ( 1l < < 53 ) ; } the hedge " approximately " is used in the foregoing description only because the next method is only approximately an unbiased source of independently chosen bits . if it were a perfect source or randomly chosen bits , then the algorithm shown would choose double values from the stated range with perfect uniformity . [ in early versions of java , the result was incorrectly calculated as : return ( ( ( long ) next ( 27 ) < < 27 ) + next ( 27 ) ) / ( double ) ( 1l < < 54 ) ; this might seem to be equivalent , if not better , but in fact it introduced a large nonuniformity because of the bias in the rounding of floating - point numbers : it was three times as likely that the low - order bit of the significand would be 0 than that it would be 1 ! this nonuniformity probably doesn ' t matter much in practice , but we strive for perfection . ]
