Ejemplo n.º 1
0
  /**
   * Generates a user-specified number of random bytes.
   *
   * @param bytes The array to fill with random bytes.
   */
  public void engineNextBytes(byte[] bytes) {
    int index = 0;
    int todo;
    byte[] output = this.remainder;

    // First use remainder from last time
    int rC = this.remCount;
    if (rC > 0) {
      todo = (bytes.length - index) < (4 - rC) ? (bytes.length - index) : (4 - rC);
      for (int i = 0; i < todo; i++, rC++) bytes[i] = output[rC];

      this.remCount += todo;
      index += todo;
    }

    // If we need more bytes, get them
    while (index < bytes.length) {
      output = ISAACEngine.toByteArray(this.isaac.nextInt());

      todo = (bytes.length - index) > 4 ? 4 : (bytes.length - index);
      for (int i = 0; i < todo; i++, index++) bytes[index] = output[i];

      this.remCount += todo;
    }

    // Store remainder for next time
    this.remainder = output;
    this.remCount %= 4;
  }
Ejemplo n.º 2
0
 /**
  * Reseeds this random object. The given seed supplements, rather than replaces, the existing
  * seed.
  *
  * @param seed The seed.
  */
 public void engineSetSeed(byte[] seed) {
   this.isaac.supplementSeed(ISAACEngine.packToIntArray(seed));
 }
Ejemplo n.º 3
0
 /**
  * Creates a new instance and seeds it with random data obtained from <code>
  * java.security.SecureRandom</code>'s <code>getSeed()</code> method.
  */
 public ISAACEngine() {
   byte[] temp = new byte[1024]; // SecureRandom.getSeed (1024);
   new SecureRandom().nextBytes(temp);
   this.isaac = new ISAACAlgorithm(ISAACEngine.packToIntArray(temp));
 }