All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object
|
+----java.util.Random
|
+----java.security.SecureRandom
This class provides a crytpographically strong pseudo-random number generator based on the SHA-1 hash algorithm.
The calls inherited from Random will be implemented in terms of the strengthened functionality.
long seed
.
public SecureRandom()
The first time this constructor is called in a given Virtual Machine, it may take several seconds of CPU time to seed the generator, depending on the underlying hardware. Successive calls run quickly because they rely on the same (internal) pseudo-random number generator for their seed bits.
The seeding procedure implemented by this constructor ensures that the sequence of pseudo-random bytes produced by each SecureRandom instance yields no useful information about the byte-sequence produced by any other instance. If however, the user wishes to produce multiple instances with truly unrelated seeds, the following code yields the desired result (at substantial CPU cost per instance!):
SecureRandom rnd = new SecureRandom(SecureRandom.getSeed(20));
public SecureRandom(byte seed[])
public synchronized void setSeed(byte seed[])
public void setSeed(long seed)
long seed
. The given seed supplements,
rather than replaces, the existing seed. Thus, repeated calls
are guaranteed never to reduce randomness.
This method is defined for compatibility with
java.util.Random
.
public synchronized void nextBytes(byte bytes[])
protected final int next(int numBits)
java.util.Random
method, and serves
to provide a source of random bits to all of the methods inherited
from that class (for example, nextInt
,
nextLong
, and nextFloat
).
numBits
<= 32.
public static byte[] getSeed(int numBytes)
All Packages Class Hierarchy This Package Previous Next Index