org.logi.crypto.random
Class RandomFromStream
java.lang.Object
|
+--java.util.Random
|
+--org.logi.crypto.random.RandomFromStream
- 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();
}
- Author:
- Logi Ragnarsson
(logir@logi.org)
- See Also:
- Serialized Form
Constructor Summary |
RandomFromStream(java.io.InputStream 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 |
RandomFromStream
public RandomFromStream(java.io.InputStream in)
- Create a new RandomFromStream obejct. Random bits are read from
in
nextBytes
public void nextBytes(byte[] bytes)
- Generates a user specified number of random bytes.
- Overrides:
- nextBytes in class java.util.Random
Copyright 1997-2000 Logi Ragnarsson