Class SecureRandom

java.lang.Object
java.util.Random
java.security.SecureRandom

public class SecureRandom extends Random

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 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)
      Description copied from class: Random
      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.
      Overrides:
      setSeed in class Random
    • setSeed

      public void setSeed(byte[] seed)
      Ignored: see the class description.
    • nextBytes

      public void nextBytes(byte[] bytes)
      Description copied from class: Random
      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.
      Overrides:
      nextBytes in class Random
    • generateSeed

      public byte[] generateSeed(int numBytes)
      numBytes fresh random bytes, where the JDK answers seed material.
    • next

      protected int next(int bits)
      Description copied from class: Random
      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.
      Overrides:
      next in class Random
    • getAlgorithm

      public String getAlgorithm()