This class generates cryptographic-quality pseudorandom bytes. Although SecureRandom defines public constructors, the preferred technique for obtaining a SecureRandom object is to call one of the static getInstance( ) factory methods , specifying the desired pseudorandom number-generation algorithm, and, optionally , the desired provider of that algorithm. Sun's implementation of Java ships with an algorithm named "SHA1PRNG" in the "SUN" provider. Once you have obtained a SecureRandom object, call nextBytes( ) to fill an array with pseudorandom bytes. You can also call any of the methods defined by the Random superclass to obtain random numbers . The first time one of these methods is called, the SecureRandom( ) method uses its generateSeed( ) method to seed itself. If you have a source of random or very high-quality pseudorandom bytes, you may provide your own seed by calling setSeed( ) . Repeated calls to setSeed( ) augment the existing seed instead of replacing it. You can also call generateSeed( ) to generate seeds for use with other pseudorandom generators. generateSeed( ) may use a different algorithm than nextBytes( ) and may produce higher-quality randomness, usually at the expense of increased computation time. Figure 14-36. java.security.SecureRandompublic class SecureRandom extends java.util.Random { // Public Constructors public SecureRandom ( ); public SecureRandom (byte[ ] seed ); // Protected Constructors 1.2 protected SecureRandom (SecureRandomSpi secureRandomSpi , Provider provider ); // Public Class Methods 1.2 public static SecureRandom getInstance (String algorithm ) throws NoSuchAlgorithmException; 1.2 public static SecureRandom getInstance (String algorithm , String provider ) throws NoSuchAlgorithmException, NoSuchProviderException; 1.4 public static SecureRandom getInstance (String algorithm , Provider provider ) throws NoSuchAlgorithmException; public static byte[ ] getSeed (int numBytes ); // Public Instance Methods 1.2 public byte[ ] generateSeed (int numBytes ); 5.0 public String getAlgorithm ( ); default:"NativePRNG" 1.2 public final Provider getProvider ( ); public void setSeed (byte[ ] seed ); synchronized // Public Methods Overriding Random public void nextBytes (byte[ ] bytes ); synchronized public void setSeed (long seed ); // Protected Methods Overriding Random protected final int next (int numBits ); } Passed ToToo many methods to list. Type OfSignatureSpi.appRandom |