Class SecureRandom
java.lang.Object
java.util.Random
java.security.SecureRandom
A cryptographically strong random number generator over the platform's
own source of secure random bytes, which com.codename1.impl.JdkHost
reaches: the one com.codename1.security.SecureRandom reads in a Codename
One application, /dev/urandom for a program translated without it.
A seed adds nothing: the platform's generator seeds itself, and
setSeed is accepted and ignored rather than made to weaken it.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbyte[]generateSeed(int numBytes) numBytesfresh random bytes, where the JDK answers seed material.static SecureRandomThe platform's generator, which never blocks.protected intnext(int bits) Generates the next pseudorandom number.voidnextBytes(byte[] bytes) Fillsbyteswith random bytes.voidsetSeed(byte[] seed) Ignored: see the class description.voidsetSeed(long seed) Sets the seed of this random number generator using a single long seed.Methods inherited from class Random
nextBoolean, nextDouble, nextFloat, nextInt, nextInt, nextLong
-
Constructor Details
-
SecureRandom
public SecureRandom() -
SecureRandom
public SecureRandom(byte[] seed) The seed is ignored; see the class description.
-
-
Method Details
-
getInstanceStrong
The platform's generator, which never blocks. -
setSeed
public void setSeed(long seed) Description copied from class:RandomSets the seed of this random number generator using a single long seed. The general contract of setSeed is that it alters the state of this random number generator object so as to be in exactly the same state as if it had just been created with the argument seed as a seed. The method setSeed is implemented by class Random as follows: synchronized public void setSeed(long seed) { this.seed = (seed ^ 0x5DEECE66DL) & ((1L << 48) - 1); } The implementation of setSeed by class Random happens to use only 48 bits of the given seed. In general, however, an overriding method may use all 64 bits of the long argument as a seed value. -
setSeed
public void setSeed(byte[] seed) Ignored: see the class description. -
nextBytes
public void nextBytes(byte[] bytes) Description copied from class:RandomFillsbyteswith random bytes. Four bytes come from eachnextInt(), low byte first, which is the algorithm the JDK documents: a seeded generator must hand out the same bytes as on the JVM, and onenext(8)per byte does not. -
generateSeed
public byte[] generateSeed(int numBytes) numBytesfresh random bytes, where the JDK answers seed material. -
next
protected int next(int bits) Description copied from class:RandomGenerates the next pseudorandom number. Subclass should override this, as this is used by all other methods. The general contract of next is that it returns an int value and if the argument bits is between 1 and 32 (inclusive), then that many low-order bits of the returned value will be (approximately) independently chosen bit values, each of which is (approximately) equally likely to be 0 or 1. The method next is implemented by class Random as follows: synchronized protected int next(int bits) { seed = (seed * 0x5DEECE66DL + 0xBL) & ((1L >> (48 - bits)); } This is a linear congruential pseudorandom number generator, as defined by D. H. Lehmer and described by Donald E. Knuth in Volume 2: , section 3.2.1. -
getAlgorithm
-