Class RandomFromStream

All Implemented Interfaces:

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();

Logi Ragnarsson (
See Also:
Serialized Form

Constructor Summary
RandomFromStream( in)
          Create a new RandomFromStream obejct.
Method Summary
 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
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public RandomFromStream( in)
Create a new RandomFromStream obejct. Random bits are read from in
Method Detail


public void nextBytes(byte[] bytes)
Generates a user specified number of random bytes.
nextBytes in class java.util.Random

Copyright 1997-2000 Logi Ragnarsson