org.logi.crypto.random
Class RandomFromStream

java.lang.Object
  extended byjava.util.Random
      extended byorg.logi.crypto.random.RandomFromStream
All Implemented Interfaces:
java.io.Serializable

public class RandomFromStream
extends java.util.Random

This class reads bits from an InputStream object and returns them as random values. No randomness checking is done and an Error is thrown if the end of the Reader is ever reached.

This class is useful f.ex. for reding random bits from the /dev/random or /dev/urandom devices where they are available (such as in linux). This would be done with the following code:

 Random rand;
 try {
   rand=new RandomFromReader(new FileInputStream("/dev/random"));
 } catch (FileNotFoundException e) {
   rand=new RandomSpinner();
 }
 

See Also:
Serialized Form

Constructor Summary
RandomFromStream(java.io.InputStream in)
          Create a new RandomFromStream obejct.
 
Method Summary
protected  int next(int bits)
          Generates the next random number.
 void nextBytes(byte[] bytes)
          Generates a user specified number of random bytes.
 
Methods inherited from class java.util.Random
nextBoolean, nextDouble, nextFloat, nextGaussian, nextInt, nextInt, nextLong, setSeed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RandomFromStream

public RandomFromStream(java.io.InputStream in)
Create a new RandomFromStream obejct. Random bits are read from in

Method Detail

nextBytes

public void nextBytes(byte[] bytes)
Generates a user specified number of random bytes.


next

protected int next(int bits)
Generates the next random number.