public class SecureRandom extends Random
Constructor and Description |
---|
SecureRandom()
Constructs a secure random number generator (RNG) implementing the default random number algorithm.
|
SecureRandom(byte[] seed)
Constructs a secure random number generator (RNG) implementing the default random number algorithm.
|
Modifier and Type | Method and Description |
---|---|
byte[] |
generateSeed(int numBytes)
Returns the given number of seed bytes, computed using the seed generation algorithm that this class uses to seed
itself.
|
protected int |
next(int numBits)
Generates an integer containing the user-specified number of pseudo-random bits (right justified, with leading
zeros).
|
void |
nextBytes(byte[] bytes)
Generates a user-specified number of random bytes.
|
void |
setSeed(byte[] seed)
Reseeds this random object.
|
void |
setSeed(long seed)
Reseeds this random object, using the eight bytes contained in the given
long seed . |
nextBoolean, nextDouble, nextFloat, nextGaussian, nextInt, nextInt, nextLong
public SecureRandom()
The returned SecureRandom object has not been seeded. To seed the returned object, call the setSeed
method. If setSeed
is not called, the first call to nextBytes
will force the SecureRandom object
to seed itself. This self-seeding will not occur if setSeed
was previously called.
public SecureRandom(byte[] seed)
seed
- the seed.public void setSeed(byte[] seed)
seed
- the 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 void nextBytes(byte[] bytes)
If a call to setSeed
had not occurred previously, the first call to this method forces this SecureRandom
object to seed itself. This self-seeding will not occur if setSeed
was previously called.
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
).public byte[] generateSeed(int numBytes)
numBytes
- the number of seed bytes to generate.