|
APCS Java Subset | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectap.java.util.Random
This class supports generation of pseudorandom numbers. The APCS Java subset specifies two methods and one constructor as shown below.
The constructor from a specified seed is useful to recreate the same sequence of random numbers, but isn't in the subset. The default constructor uses the current time to set the seed.
Random r = new Random(1123); // set from long value
Constructor Summary | |
Random()
Constructs a pseudorandom number generator using the current time as the seed (as returned by System.currentTimeMillis() . |
Method Summary | |
double |
nextDouble()
Returns a uniformly distributed double. |
int |
nextInt(int n)
Returns a uniformly distributed pseudorandom integer. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Random()
System.currentTimeMillis()
.
Method Detail |
public int nextInt(int n)
[0..n)
is equally likely
to be returned. Note that 0/zero can be returned, but the largest
value that can returned is n-1
.
n
- is the exclusive upperbound on the range of values returned.
public double nextDouble()
[0.0 .. 1.0)
,
i.e., 0 can be returned but 1 cannot be returned.
|
unofficial documentation for the APCS Java Subset | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |