Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.bouncycastle.crypto.prng;

Takes bytes generated by an underling RandomGenerator and reverses the order in each small window (of configurable size).

Access to internals is synchronized so a single one of these can be shared.

  
 public class ReversedWindowGenerator
     implements RandomGenerator
 {
     private final RandomGenerator generator;
 
     private byte[] window;
     private int windowCount;
 
     public ReversedWindowGenerator(
         RandomGenerator generator,
         int             windowSize)
     {
         if (generator == null)
         {
             throw new IllegalArgumentException("generator cannot be null");
         }
         if (windowSize < 2)
         {
             throw new IllegalArgumentException("windowSize must be at least 2");
         }
 
         this. = generator;
         this. = new byte[windowSize];
     }

    
Add more seed material to the generator.

Parameters:
seed a byte array to be mixed into the generator's state.
 
     public void addSeedMaterial(
         byte[] seed)
     {
         synchronized (this)
         {
              = 0;
             .addSeedMaterial(seed);
         }
     }

    
Add more seed material to the generator.

Parameters:
seed a long value to be mixed into the generator's state.
 
     public void addSeedMaterial(
         long seed)
     {
         synchronized (this)
         {
              = 0;
             .addSeedMaterial(seed);
         }
     }

    
Fill bytes with random values.

Parameters:
bytes byte array to be filled.
 
     public void nextBytes(
         byte[] bytes)
     {
         doNextBytes(bytes, 0, bytes.length);
     }

    
Fill part of bytes with random values.

Parameters:
bytes byte array to be filled.
start index to start filling at.
len length of segment to fill.
 
     public void nextBytes(
         byte[]  bytes,
         int     start,
         int     len)
     {
         doNextBytes(bytesstartlen);
     }
 
     private void doNextBytes(
         byte[]  bytes,
         int     start,
         int     len)
     {
         synchronized (this)
         {
             int done = 0;
             while (done < len)
            {
                if ( < 1)
                {
                    .nextBytes(, 0, .);
                     = .;
                }
                bytes[start + done++] = [--];
            }
        }
    }
New to GrepCode? Check out our FAQ X