org.xlattice.crypto
Class CryptoRNG

java.lang.Object
  extended by org.xlattice.crypto.CryptoRNG

public class CryptoRNG
extends java.lang.Object

Random number generator with crypto-level security. Wherever a value is described as "random" in the comments on methods, it should be understood that the value is a pseudo- random value and that the set of such values is very nearly uniformly distributed over the interval in question, except that Gaussian values have a distribution which is very nearly Gaussian. This should be one of two classes implementing an RNG interface, with the other class offering a lower-quality (and therefore cheaper) pseudo-random number sequence. XXX This implementation is the thinnest of wrappers around the XXX JCA SecureRandom class.

Author:
Jim Dixon

Constructor Summary
CryptoRNG()
           
CryptoRNG(byte[] seed)
           
 
Method Summary
 boolean nextBoolean()
           
 void nextBytes(byte[] b)
          Fills the byte array with random bytes.
 double nextDouble()
           
 float nextFloat()
           
 double nextGaussian()
          Returns a random value from a Gaussian sequence with mean 0.0 and standard deviation 1.0.
 int nextInt()
           
 int nextInt(int n)
          Returns a pseudo-random value between 0 (inclusive) and n (exclusive).
 long nextLong()
           
 void reseed(byte[] seed)
          Reseed the random number generator using the binary value passed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CryptoRNG

public CryptoRNG()

CryptoRNG

public CryptoRNG(byte[] seed)
Method Detail

nextBoolean

public boolean nextBoolean()

nextBytes

public void nextBytes(byte[] b)
Fills the byte array with random bytes.


nextDouble

public double nextDouble()
Returns:
a random value between 0.0 inclusive and 1.0 exclusive

nextFloat

public float nextFloat()
Returns:
a random value between 0.0 inclusive and 1.0 exclusive

nextGaussian

public double nextGaussian()
Returns a random value from a Gaussian sequence with mean 0.0 and standard deviation 1.0.


nextInt

public int nextInt()

nextInt

public int nextInt(int n)
Returns a pseudo-random value between 0 (inclusive) and n (exclusive).


nextLong

public long nextLong()

reseed

public void reseed(byte[] seed)
Reseed the random number generator using the binary value passed. This is guaranteed not to reduce the randomness of the generator. The new seed value affects but does not reset it.