protected synchronized void engineNextBytes(byte[] bytes){
  int i, n;
  long bits;
  int nextByteToReturn;
  int lastWord;
  final int extrabytes=7;
  if (bytes == null) {
    throw new NullPointerException("bytes == null");
  }
  lastWord=seed[BYTES_OFFSET] == 0 ? 0 : (seed[BYTES_OFFSET] + extrabytes) >> 3 - 1;
  if (state == UNDEFINED) {
    updateSeed(getRandomBytes(DIGEST_LENGTH));
    nextBIndex=HASHBYTES_TO_USE;
    lastWord=seed[BYTES_OFFSET] == 0 ? 0 : (seed[BYTES_OFFSET] + extrabytes) >> 3 - 1;
  }
 else   if (state == SET_SEED) {
    System.arraycopy(seed,HASH_OFFSET,copies,HASHCOPY_OFFSET,EXTRAFRAME_OFFSET);
    for (i=lastWord + 3; i < FRAME_LENGTH + 2; i++) {
      seed[i]=0;
    }
    bits=(seedLength << 3) + 64;
    if (seed[BYTES_OFFSET] < MAX_BYTES) {
      seed[14]=(int)(bits >>> 32);
      seed[15]=(int)(bits & 0xFFFFFFFF);
    }
 else {
      copies[EXTRAFRAME_OFFSET + 14]=(int)(bits >>> 32);
      copies[EXTRAFRAME_OFFSET + 15]=(int)(bits & 0xFFFFFFFF);
    }
    nextBIndex=HASHBYTES_TO_USE;
  }
  state=NEXT_BYTES;
  if (bytes.length == 0) {
    return;
  }
  nextByteToReturn=0;
  n=(HASHBYTES_TO_USE - nextBIndex) < (bytes.length - nextByteToReturn) ? HASHBYTES_TO_USE - nextBIndex : bytes.length - nextByteToReturn;
  if (n > 0) {
    System.arraycopy(nextBytes,nextBIndex,bytes,nextByteToReturn,n);
    nextBIndex+=n;
    nextByteToReturn+=n;
  }
  if (nextByteToReturn >= bytes.length) {
    return;
  }
  n=seed[BYTES_OFFSET] & 0x03;
  for (; ; ) {
    if (n == 0) {
      seed[lastWord]=(int)(counter >>> 32);
      seed[lastWord + 1]=(int)(counter & 0xFFFFFFFF);
      seed[lastWord + 2]=END_FLAGS[0];
    }
 else {
      seed[lastWord]|=(int)((counter >>> RIGHT1[n]) & MASK[n]);
      seed[lastWord + 1]=(int)((counter >>> RIGHT2[n]) & 0xFFFFFFFF);
      seed[lastWord + 2]=(int)((counter << LEFT[n]) | END_FLAGS[n]);
    }
    if (seed[BYTES_OFFSET] > MAX_BYTES) {
      copies[EXTRAFRAME_OFFSET]=seed[FRAME_LENGTH];
      copies[EXTRAFRAME_OFFSET + 1]=seed[FRAME_LENGTH + 1];
    }
    SHA1Impl.computeHash(seed);
    if (seed[BYTES_OFFSET] > MAX_BYTES) {
      System.arraycopy(seed,0,copies,FRAME_OFFSET,FRAME_LENGTH);
      System.arraycopy(copies,EXTRAFRAME_OFFSET,seed,0,FRAME_LENGTH);
      SHA1Impl.computeHash(seed);
      System.arraycopy(copies,FRAME_OFFSET,seed,0,FRAME_LENGTH);
    }
    counter++;
    int j=0;
    for (i=0; i < EXTRAFRAME_OFFSET; i++) {
      int k=seed[HASH_OFFSET + i];
      nextBytes[j]=(byte)(k >>> 24);
      nextBytes[j + 1]=(byte)(k >>> 16);
      nextBytes[j + 2]=(byte)(k >>> 8);
      nextBytes[j + 3]=(byte)(k);
      j+=4;
    }
    nextBIndex=0;
    j=HASHBYTES_TO_USE < (bytes.length - nextByteToReturn) ? HASHBYTES_TO_USE : bytes.length - nextByteToReturn;
    if (j > 0) {
      System.arraycopy(nextBytes,0,bytes,nextByteToReturn,j);
      nextByteToReturn+=j;
      nextBIndex+=j;
    }
    if (nextByteToReturn >= bytes.length) {
      break;
    }
  }
}

protected synchronized void engineNextBytes ( byte [ ] bytes ) { int i , n ; long bits ; int nextByteToReturn ; int lastWord ; final int extrabytes = 7 ; if ( bytes == null ) { throw new NullPointerException ( "bytes == null" ) ; } lastWord = seed [ BYTES_OFFSET ] == 0 ? 0 : ( seed [ BYTES_OFFSET ] + extrabytes ) > > 3 - 1 ; if ( state == UNDEFINED ) { updateSeed ( getRandomBytes ( DIGEST_LENGTH ) ) ; nextBIndex = HASHBYTES_TO_USE ; lastWord = seed [ BYTES_OFFSET ] == 0 ? 0 : ( seed [ BYTES_OFFSET ] + extrabytes ) > > 3 - 1 ; } else if ( state == SET_SEED ) { System . arraycopy ( seed , HASH_OFFSET , copies , HASHCOPY_OFFSET , EXTRAFRAME_OFFSET ) ; for ( i = lastWord + 3 ; i < FRAME_LENGTH + 2 ; i ++ ) { seed [ i ] = 0 ; } bits = ( seedLength << 3 ) + 64 ; if ( seed [ BYTES_OFFSET ] < MAX_BYTES ) { seed [ 14 ] = ( int ) ( bits > > > 32 ) ; seed [ 15 ] = ( int ) ( bits & 0xFFFFFFFF ) ; } else { copies [ EXTRAFRAME_OFFSET + 14 ] = ( int ) ( bits > > > 32 ) ; copies [ EXTRAFRAME_OFFSET + 15 ] = ( int ) ( bits & 0xFFFFFFFF ) ; } nextBIndex = HASHBYTES_TO_USE ; } state = NEXT_BYTES ; if ( bytes . length == 0 ) { return ; } nextByteToReturn = 0 ; n = ( HASHBYTES_TO_USE - nextBIndex ) < ( bytes . length - nextByteToReturn ) ? HASHBYTES_TO_USE - nextBIndex : bytes . length - nextByteToReturn ; if ( n > 0 ) { System . arraycopy ( nextBytes , nextBIndex , bytes , nextByteToReturn , n ) ; nextBIndex += n ; nextByteToReturn += n ; } if ( nextByteToReturn >= bytes . length ) { return ; } n = seed [ BYTES_OFFSET ] & 0x03 ; for ( ; ; ) { if ( n == 0 ) { seed [ lastWord ] = ( int ) ( counter > > > 32 ) ; seed [ lastWord + 1 ] = ( int ) ( counter & 0xFFFFFFFF ) ; seed [ lastWord + 2 ] = END_FLAGS [ 0 ] ; } else { seed [ lastWord ] |= ( int ) ( ( counter > > > RIGHT1 [ n ] ) & MASK [ n ] ) ; seed [ lastWord + 1 ] = ( int ) ( ( counter > > > RIGHT2 [ n ] ) & 0xFFFFFFFF ) ; seed [ lastWord + 2 ] = ( int ) ( ( counter << LEFT [ n ] ) | END_FLAGS [ n ] ) ; } if ( seed [ BYTES_OFFSET ] > MAX_BYTES ) { copies [ EXTRAFRAME_OFFSET ] = seed [ FRAME_LENGTH ] ; copies [ EXTRAFRAME_OFFSET + 1 ] = seed [ FRAME_LENGTH + 1 ] ; } SHA1Impl . computeHash ( seed ) ; if ( seed [ BYTES_OFFSET ] > MAX_BYTES ) { System . arraycopy ( seed , 0 , copies , FRAME_OFFSET , FRAME_LENGTH ) ; System . arraycopy ( copies , EXTRAFRAME_OFFSET , seed , 0 , FRAME_LENGTH ) ; SHA1Impl . computeHash ( seed ) ; System . arraycopy ( copies , FRAME_OFFSET , seed , 0 , FRAME_LENGTH ) ; } counter ++ ; int j = 0 ; for ( i = 0 ; i < EXTRAFRAME_OFFSET ; i ++ ) { int k = seed [ HASH_OFFSET + i ] ; nextBytes [ j ] = ( byte ) ( k > > > 24 ) ; nextBytes [ j + 1 ] = ( byte ) ( k > > > 16 ) ; nextBytes [ j + 2 ] = ( byte ) ( k > > > 8 ) ; nextBytes [ j + 3 ] = ( byte ) ( k ) ; j += 4 ; } nextBIndex = 0 ; j = HASHBYTES_TO_USE < ( bytes . length - nextByteToReturn ) ? HASHBYTES_TO_USE : bytes . length - nextByteToReturn ; if ( j > 0 ) { System . arraycopy ( nextBytes , 0 , bytes , nextByteToReturn , j ) ; nextByteToReturn += j ; nextBIndex += j ; } if ( nextByteToReturn >= bytes . length ) { break ; } } }
writes random bytes into an array supplied . bits in a byte are from left to right . < br > to generate random bytes , the " expansion of source bits " method is used , that is , the current seed with a 64 - bit counter appended is used to compute new bits . the counter is incremented by 1 for each 20 - byte output . < br > the method overrides enginenextbytes in class securerandomspi .
