APCS Java Subset

ap.java.util
Class Random

java.lang.Object
  extended byap.java.util.Random

public class Random
extends java.lang.Object

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

Random

public Random()
Constructs a pseudorandom number generator using the current time as the seed (as returned by System.currentTimeMillis().

Method Detail

nextInt

public int nextInt(int n)
Returns a uniformly distributed pseudorandom integer. Each value in the range [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.

Parameters:
n - is the exclusive upperbound on the range of values returned.
Returns:
the next pseudorandom integer value in the specified range from the sequence generated by this random number generator

nextDouble

public double nextDouble()
Returns a uniformly distributed double. The returned value is in the range [0.0 .. 1.0), i.e., 0 can be returned but 1 cannot be returned.

Returns:
the next pseudorandom double value in the sequence generated by this random number generator

unofficial documentation for the APCS Java Subset