com.pholser.junit.quickcheck.random
Class SourceOfRandomness

java.lang.Object
  extended by com.pholser.junit.quickcheck.random.SourceOfRandomness

public class SourceOfRandomness
extends Object

A source of randomness, fed to Generators so they can produce random values for theory parameters.


Constructor Summary
SourceOfRandomness(Random delegate)
          Makes a new source of randomness.
 
Method Summary
 BigInteger nextBigInteger(int numberOfBits)
          Gives a random BigInteger representable by the given number of bits.
 boolean nextBoolean()
           
 byte nextByte(byte min, byte max)
          Gives a random byte value v such that min <= v <= max, uniformly distributed across the interval [min, max].
 void nextBytes(byte[] bytes)
           
 byte[] nextBytes(int count)
          Gives an array of a given length containing random bytes.
 char nextChar(char min, char max)
          Gives a random char value v such that min <= v <= max, uniformly distributed across the interval [min, max].
 double nextDouble()
           
 double nextDouble(double min, double max)
          Gives a random double value v such that min <= v < max.
 float nextFloat()
           
 float nextFloat(float min, float max)
          Gives a random float value v such that min <= v < max.
 double nextGaussian()
           
 int nextInt()
           
 int nextInt(int n)
           
 int nextInt(int min, int max)
          Gives a random int value v such that min <= v <= max, uniformly distributed across the interval [min, max].
 long nextLong()
           
 long nextLong(long min, long max)
          Gives a random long value v such that min <= v <= max, uniformly distributed across the interval [min, max].
 short nextShort(short min, short max)
          Gives a random short value v such that min <= v <= max, uniformly distributed across the interval [min, max].
 void setSeed(long seed)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SourceOfRandomness

public SourceOfRandomness(Random delegate)
Makes a new source of randomness.

Parameters:
delegate - a JDK source of randomness, to which the new instance will delegate
Method Detail

nextBoolean

public boolean nextBoolean()
See Also:
Random.nextBoolean()

nextBytes

public void nextBytes(byte[] bytes)
See Also:
Random.nextBytes(byte[])

nextDouble

public double nextDouble()
See Also:
Random.nextDouble()

nextFloat

public float nextFloat()
See Also:
Random.nextFloat()

nextGaussian

public double nextGaussian()
See Also:
Random.nextGaussian()

nextInt

public int nextInt()
See Also:
Random.nextInt()

nextInt

public int nextInt(int n)
See Also:
Random.nextInt(int)

nextLong

public long nextLong()
See Also:
Random.nextLong()

setSeed

public void setSeed(long seed)
See Also:
Random.setSeed(long)

nextByte

public byte nextByte(byte min,
                     byte max)
Gives a random byte value v such that min <= v <= max, uniformly distributed across the interval [min, max].

Parameters:
min - lower bound of the desired range
max - upper bound of the desired range
Returns:
a random value

nextShort

public short nextShort(short min,
                       short max)
Gives a random short value v such that min <= v <= max, uniformly distributed across the interval [min, max].

Parameters:
min - lower bound of the desired range
max - upper bound of the desired range
Returns:
a random value

nextChar

public char nextChar(char min,
                     char max)
Gives a random char value v such that min <= v <= max, uniformly distributed across the interval [min, max].

Parameters:
min - lower bound of the desired range
max - upper bound of the desired range
Returns:
a random value

nextInt

public int nextInt(int min,
                   int max)
Gives a random int value v such that min <= v <= max, uniformly distributed across the interval [min, max].

Parameters:
min - lower bound of the desired range
max - upper bound of the desired range
Returns:
a random value

nextLong

public long nextLong(long min,
                     long max)
Gives a random long value v such that min <= v <= max, uniformly distributed across the interval [min, max].

Parameters:
min - lower bound of the desired range
max - upper bound of the desired range
Returns:
a random value

nextFloat

public float nextFloat(float min,
                       float max)

Gives a random float value v such that min <= v < max.

This naive implementation takes a random float value from Random.nextFloat() and scales/shifts the value into the desired range. This may give surprising results for large ranges.

Parameters:
min - lower bound of the desired range
max - upper bound of the desired range
Returns:
a random value

nextDouble

public double nextDouble(double min,
                         double max)

Gives a random double value v such that min <= v < max.

This naive implementation takes a random double value from Random.nextDouble() and scales/shifts the value into the desired range. This may give surprising results for large ranges.

Parameters:
min - lower bound of the desired range
max - upper bound of the desired range
Returns:
a random value

nextBytes

public byte[] nextBytes(int count)
Gives an array of a given length containing random bytes.

Parameters:
count - the desired length of the random byte array
Returns:
random bytes
See Also:
Random.nextBytes(byte[])

nextBigInteger

public BigInteger nextBigInteger(int numberOfBits)
Gives a random BigInteger representable by the given number of bits.

Parameters:
numberOfBits - the desired number of bits
Returns:
a random BigInteger
See Also:
BigInteger.BigInteger(int, java.util.Random)


Copyright © 2013. All Rights Reserved.