THE PACKAGE JAVA.UTIL
java.util.Random
21.9
21.9.10
public float nextFloat()
The general contract of
nextFloat
 is that one
float
 value, chosen (approxi 
mately) uniformly from the range
0.0f
 (inclusive) to
1.0f
 (exclusive), is pseudo 
randomly generated and returned. All
24
2
possible
float
 values of the form
m
24
2
 24
, where
m
 is a positive integer less than 2 , are produced with (approxi 
mately) equal probability.
The method
setSeed
 is implemented by class
Random
 as follows:
public float nextFloat() {
return next(24) / ((float)(1 << 24));
}
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
float
 values from the stated range with perfect uniformity.
[In early versions of Java, the result was incorrectly calculated as:
return next(30) / ((float)(1 << 30));
This might seem to be equivalent, if not better, but in fact it introduced a slight
nonuniformity because of the bias in the rounding of floating point numbers: it
was slightly more likely that the low order bit of the significand would be
0
 than
that it would be
1
.]
21.9.11
public double nextDouble()
The general contract of
nextDouble
 is that one
double
 value, chosen (approxi 
mately) uniformly from the range
0.0d
 (inclusive) to
1.0d
 (exclusive), is pseudo 
randomly generated and returned. All
53
2
possible
float
 values of the form
 53
53
m
2
, where
m
 is a positive integer less than 2 , are produced with (approxi 
mately) equal probability.
The method
setSeed
 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:
649






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

java hosting

 

Our partners: PHP: Hypertext Preprocessor Best Web Hosting Java Web Hosting Inexpensive Web Hosting  Jsp Web Hosting

Cheapest Web Hosting Jsp Hosting Cheap Hosting

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved