Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.
public class 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.
Constructors
public SecureRandom() | |
public SecureRandom(byte[] seed) | The seed is ignored; see the class description. |
Methods
public static SecureRandom getInstanceStrong() | The platform’s generator, which never blocks. |
public void setSeed(long seed) | Sets the seed of this random number generator using a single long seed. |
public void setSeed(byte[] seed) | Ignored: see the class description. |
public void nextBytes(byte[] bytes) | Fills bytes with random bytes. |
public byte[] generateSeed(int numBytes) | numBytes fresh random bytes, where the JDK answers seed material. |
protected int next(int bits) | Generates the next pseudorandom number. |
public String getAlgorithm() |
Inherited methods
From Random
nextDouble, nextFloat, nextInt, nextInt, nextLong, nextBoolean
Constructor details
SecureRandom
public SecureRandom()SecureRandom
public SecureRandom(byte[] seed)The seed is ignored; see the class description.
Method details
getInstanceStrong
public static SecureRandom getInstanceStrong()The platform’s generator, which never blocks.
setSeed
public void setSeed(long seed)Sets 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)Fills
bytes with random bytes. Four bytes come from each nextInt(),
low byte first, which is the algorithm the JDK documents: a seeded
generator must hand out the same bytes as on the JVM, and one next(8)
per byte does not.generateSeed
public byte[] generateSeed(int numBytes)numBytes fresh random bytes, where the JDK answers seed material.next
protected int next(int bits)Generates 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
public String getAlgorithm()