Team LiB
Previous Section Next Section

Randomjava.util

Java 1.0serializable

This class implements a pseudorandom number generator suitable for games and similar applications. If you need a cryptographic-strength source of pseudorandomness, see java.security.SecureRandom. nextdouble( ) and nextFloat( ) return a value between 0.0 and 1.0. nextLong( ) and the no-argument version of nextInt( ) return long and int values distributed across the range of those data types. As of Java 1.2, if you pass an argument to nextInt( ), it returns a value between zero (inclusive) and the specified number (exclusive). nextGaussian( ) returns pseudorandom floating-point values with a Gaussian distribution; the mean of the values is 0.0 and the standard deviation is 1.0. nextBoolean( ) returns a pseudorandom boolean value, and nextBytes( ) fills in the specified byte array with pseudorandom bytes. You can use the setSeed( ) method or the optional constructor argument to initialize the pseudorandom number generator with some variable seed value other than the current time (the default) or with a constant to ensure a repeatable sequence of pseudorandomness.

Figure 16-52. java.util.Random


public class Random implements Serializable {
// Public Constructors
     public Random( );  
     public Random(long seed);  
// Public Instance Methods
1.2  public boolean nextBoolean( );  
1.1  public void nextBytes(byte[ ] bytes);  
     public double nextDouble( );  
     public float nextFloat( );  
     public double nextGaussian( );                        synchronized
     public int nextInt( );  
1.2  public int nextInt(int n);  
     public long nextLong( );  
     public void setSeed(long seed);                     synchronized
// Protected Instance Methods
1.1  protected int next(int bits);  
}

Subclasses

java.security.SecureRandom

Passed To

java.math.BigInteger.{BigInteger( ), probablePrime( )}, Collections.shuffle( )

    Team LiB
    Previous Section Next Section